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 99 del file sfat_append.c.

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

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 32 del file sfat_append.c.

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


Documentazione delle variabili

struttura rappresentante un messaggio tra client e server

Definizione alla linea 19 del file sfat_append.c.

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 20 del file sfat_append.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 21 del file sfat_append.c.

Generato il Sat Jan 29 15:05:42 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3