sfat_ls.c

Vai alla documentazione di questo file.
00001 
00013 #include "Include/common.h"
00014 
00016 static void byebye();
00017 
00018 message_t       msg;            
00019 channel_t       sk_client;      
00020 char            *path;          
00031 int main(int argc, char **argv){
00032         extern message_t msg;
00033         extern channel_t sk_client;
00034         extern char * path;
00035         
00036         sk_client = 0;
00037         path = NULL;
00038         msg.buffer = NULL;
00039         
00040         if ((atexit(byebye))!=0){
00041                 errore(__FILE__,__LINE__,"sfat_ls: cannot set exit function",errno);
00042                 exit(EXIT_FAILURE);
00043         }
00044         
00045         /* Argomenti da riga di comando */
00046         if (argc<2){
00047                 fprintf(stderr,
00048                 "sfat_ls: errore nome cartella su cui listare mancante\n");
00049                 exit(EXIT_FAILURE);
00050         }
00051         
00052         if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){
00053                 errore(__FILE__,__LINE__,
00054                 "sfat_ls: error on allocate memory for 'path'",errno);
00055                 exit(EXIT_FAILURE);
00056         }
00057         strncpy(path,TMP,strlen(TMP));
00058         strncat(path,SKTNAME,strlen(SKTNAME));
00059 
00060         /* Apro la socket di comunicazione col server */
00061         if ((sk_client = openConnection(path)) == -1) {
00062                 fprintf(stderr,"sfat_ls: Errore nella apertura del socket di comunicazione\n");
00063                 exit(EXIT_FAILURE);
00064         }
00065         else if (sk_client == SFATENAMETOOLONG){
00066                 fprintf(stderr,"sfat_ls: Error Path Too Long (exceeding UNIX_PATH_MAX)\n");     
00067                 exit(EXIT_FAILURE);
00068         }
00069         
00070         msg.type = MSG_LS;
00071         msg.length = strlen(argv[1])+1;
00072         if (!(msg.buffer = strdup(argv[1]))){
00073                 errore(__FILE__,__LINE__,
00074                 "sfat_ls: error on allocate memory for 'buffer'",errno);
00075                 exit(EXIT_FAILURE);
00076         }       
00077         if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00078         if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00079         
00080         if (msg.type==MSG_OK){
00081                 printf("sfat_ls: listing %s\n", argv[1]);
00082                 if (msg.buffer!=NULL) printf(" %s\n", msg.buffer);
00083         }
00084         else exit(EXIT_FAILURE);
00085         
00086         exit(EXIT_SUCCESS);
00087         return 0;
00088 }
00089 
00090 void byebye(){
00091         extern message_t msg;
00092         extern char * path;
00093         extern channel_t sk_client;
00094         
00095         /* Chiudo la socket di comunicazione del client */
00096         if (sk_client != -1) closeConnection(sk_client);
00097                         
00098         if (msg.buffer!=NULL) free(msg.buffer);
00099         if (path!=NULL) free(path);
00100 }
Generato il Fri Jan 28 22:16:29 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3