sfat_mkfile.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;          
00033 int main(int argc, char **argv){
00034         extern message_t msg;
00035         extern channel_t sk_client;
00036         extern char * path;
00037                 
00038         sk_client = 0;
00039         path = NULL;
00040         msg.buffer = NULL;
00041         
00042         if ((atexit(byebye))!=0){
00043                 errore(__FILE__,__LINE__,"sfat_mkfile: 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_mkfile: errore non e' stato passato il nome del il file da creare\n");
00051                 exit(EXIT_FAILURE);
00052         }       
00053         
00054         if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){
00055                 errore(__FILE__,__LINE__,
00056                 "sfat_mkfile: error on allocate memory for 'path'",errno);
00057                 exit(EXIT_FAILURE);
00058         }
00059         strncpy(path,TMP,strlen(TMP));
00060         strncat(path,SKTNAME,strlen(SKTNAME));
00061         
00062         msg.type = MSG_MKFILE;
00063         msg.length = strlen(argv[1])+1;
00064         if (!(msg.buffer = strdup(argv[1]))){
00065                 errore(__FILE__,__LINE__,
00066                 "sfat_mkfile: error on allocate memory for 'buffer'",errno);
00067                 exit(EXIT_FAILURE);
00068         }
00069         
00070         /* Apro la socket di comunicazione col server */
00071         if ((sk_client = openConnection(path)) == -1) {
00072                 fprintf(stderr,"sfat_mkfile: Errore nella apertura del socket di comunicazione\n");
00073                 exit(EXIT_FAILURE);
00074         }
00075         else if (sk_client == SFATENAMETOOLONG){
00076                 fprintf(stderr,"sfat_mkfile: Error Path Too Long (exceeding UNIX_PATH_MAX)\n");         
00077                 exit(EXIT_FAILURE);
00078         }
00079         if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00080         if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00081         if (msg.type==MSG_OK)
00082                 printf("sfat_mkfile: file %s created \n", argv[1]);
00083         else exit(EXIT_FAILURE);
00084         
00085         exit(EXIT_SUCCESS);
00086         return 0;     
00087 }
00088 
00089 void byebye(){
00090         extern message_t msg;
00091         extern char * path;
00092         extern channel_t sk_client;
00093         
00094         /* Chiudo la socket di comunicazione del client */
00095         if (sk_client != -1) closeConnection(sk_client);
00096                         
00097         if (msg.buffer!=NULL) free(msg.buffer);
00098         if (path!=NULL) free(path);
00099 }
Generato il Fri Jan 28 22:16:29 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3