sfat_mkdir.c
Vai alla documentazione di questo file.00001
00012 #include "Include/common.h"
00013
00015 static void byebye();
00016
00017 message_t msg;
00018 channel_t sk_client;
00019 char *path;
00032 int main(int argc, char **argv){
00033 extern message_t msg;
00034 extern channel_t sk_client;
00035 extern char * path;
00036
00037 sk_client = 0;
00038 path = NULL;
00039 msg.buffer = NULL;
00040
00041 if ((atexit(byebye))!=0){
00042 errore(__FILE__,__LINE__,"sfat_mkdir: cannot set exit function",errno);
00043 exit(EXIT_FAILURE);
00044 }
00045
00046
00047 if (argc<2){
00048 fprintf(stderr,
00049 "sfat_mkdir: errore non e' stato passato alcun nome per la cartella da creare\n");
00050 exit(EXIT_FAILURE);
00051 }
00052
00053 if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){
00054 errore(__FILE__,__LINE__,
00055 "sfat_mkdir: error on allocate memory for 'path'",errno);
00056 exit(EXIT_FAILURE);
00057 }
00058 strncpy(path,TMP,strlen(TMP));
00059 strncat(path,SKTNAME,strlen(SKTNAME));
00060
00061 msg.type = MSG_MKDIR;
00062 msg.length = strlen(argv[1])+1;
00063 if (!(msg.buffer = malloc(msg.length))){
00064 errore(__FILE__,__LINE__,
00065 "sfat_mkdir: error on allocate memory for 'buffer'",errno);
00066 exit(EXIT_FAILURE);
00067 }
00068 memset(msg.buffer, 0x0, msg.length);
00069
00070 strncat(msg.buffer,argv[1],msg.length);
00071
00072
00073 if ((sk_client = openConnection(path)) == -1) {
00074 fprintf(stderr,"sfat_read: Errore nella apertura del socket di comunicazione\n");
00075 exit(EXIT_FAILURE);
00076 }
00077 else if (sk_client == SFATENAMETOOLONG){
00078 fprintf(stderr,"sfat_read: Error Path Too Long (exceeding UNIX_PATH_MAX)\n");
00079 exit(EXIT_FAILURE);
00080 }
00081
00082 if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00083 if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00084 if (msg.type==MSG_OK)
00085 printf("sfat_mkdir: %s created!\n", argv[1]);
00086 else exit(EXIT_FAILURE);
00087
00088 exit(EXIT_SUCCESS);
00089 return 0;
00090 }
00091
00092 void byebye(){
00093 extern message_t msg;
00094 extern char * path;
00095 extern channel_t sk_client;
00096
00097
00098 if (sk_client != -1) closeConnection(sk_client);
00099
00100 if (msg.buffer!=NULL) free(msg.buffer);
00101 if (path!=NULL) free(path);
00102 }