Riferimenti per il file sfat_append.c

#include "Include/common.h"

Vai al codice sorgente di questo file.

Funzioni

static void byebye ()
int main (int argc, char **argv)

Variabili

message_t msg
channel_t sk_client
char * path

Descrizione dettagliata

Autore:
Tranchida Giulio, No Matricola 241732
Si dichiara che il contenuto di questo file e', in ogni sua parte, opera originale dell'autore.

This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.

Definizione nel file sfat_append.c.


Documentazione delle funzioni

void byebye (  )  [static]

exit function

Definizione alla linea 98 del file sfat_append.c.

00098              {
00099         extern message_t msg;
00100         extern char * path;
00101         extern channel_t sk_client;
00102         
00103         /* Chiudo la socket di comunicazione del client */
00104         if (sk_client != -1) closeConnection(sk_client);
00105                         
00106         if (msg.buffer!=NULL) free(msg.buffer);
00107         if (path!=NULL) free(path);
00108 }

int main ( int  argc,
char **  argv 
)

Sfat append

Comando: sfat_append file string

Appende la string string (senza il terminatore finale) alla fine del file.
All'invocazione il client controlla i parametri e contatta il server inviando una richiesta di connessione sul socket.
Se la connessione ha successo il client invia una richiesta MSG_FWRITE.
Tutti gli errori sono riportati sullo standar error.

Definizione alla linea 31 del file sfat_append.c.

00031                                {
00032         extern message_t msg;
00033         extern channel_t sk_client;
00034         extern char * path;
00035         char * buffer;
00036         int sent =0;
00037         
00038         sk_client = 0;
00039         path = NULL;
00040         msg.buffer = NULL;
00041         if ((atexit(byebye))!=0){
00042                 errore(__FILE__,__LINE__,"sfat_append: cannot set exit function",errno);
00043                 exit(EXIT_FAILURE);
00044         }
00045         
00046         /* Argomenti da riga di comando */
00047         if (argc<2){
00048                 fprintf(stderr,
00049                 "sfat_append: errore non e' stato passato il nome del file\n");
00050                 exit(EXIT_FAILURE);
00051         }else if (argc<3){
00052                 fprintf(stderr,
00053                 "sfat_append: errore non e' stato passato il testo da aggiungere al file\n");
00054                 exit(EXIT_FAILURE);
00055         }
00056         
00057         if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){
00058                 errore(__FILE__,__LINE__,
00059                 "sfat_append: error on allocate memory for 'path'",errno);
00060                 exit(EXIT_FAILURE);
00061         }
00062         strncpy(path, TMP, strlen(TMP)+1);
00063         strncat(path, SKTNAME, strlen(SKTNAME));
00064         
00065         /* Apro la socket di comunicazione col server */
00066         if ((sk_client = openConnection(path)) == -1) {
00067                 fprintf(stderr,"sfat_append: Errore nella apertura del socket di comunicazione\n");
00068                 exit(EXIT_FAILURE);
00069         }
00070         else if (sk_client == SFATENAMETOOLONG){
00071                 fprintf(stderr,"sfat_append: Error Path Too Long (exceeding UNIX_PATH_MAX)\n");         
00072                 exit(EXIT_FAILURE);
00073         }
00074         
00075         /* Preparo il messaggio da inviare al server */
00076         msg.type = MSG_FWRITE;
00077         msg.length = strlen(argv[1]) + strlen(argv[2]) + 2;
00078         if (!(msg.buffer = calloc(msg.length, sizeof(char)))){
00079                 errore(__FILE__,__LINE__,
00080                 "sfat_append: error on allocate memory for 'buffer'",errno);
00081                 exit(EXIT_FAILURE);
00082         }
00083         /* Struttura del messaggio: Path\0Buf\0 */
00084         strncpy(msg.buffer, argv[1], strlen(argv[1]));
00085         buffer = msg.buffer + strlen(argv[1]) + 1;
00086         strncpy(buffer,argv[2],strlen(argv[2]));
00087         
00088         if ((sent = sendMessage(sk_client, &msg)) == -1) exit(EXIT_FAILURE);
00089         if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00090         if (msg.type==MSG_OK)
00091                 printf("sfat_append: appended \"%s\"\n", argv[2]);
00092         else exit(EXIT_FAILURE);
00093         
00094         exit(EXIT_SUCCESS);
00095         return 0;     
00096 }


Documentazione delle variabili

struttura rappresentante un messaggio tra client e server

Definizione alla linea 18 del file sfat_append.c.

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 19 del file sfat_append.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 20 del file sfat_append.c.

Generato il Fri Jan 28 22:16:29 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3