Vérifie la présence du dossier en "path", si non existant, le créer : void check_if_exist(char *path) { struct stat st; if (stat(path,&st) == -1) { if (mkdir(path,0755) == -1) { perror(path); exit(0); } } } Récupère la date au format voulu et la retourne : char *date(char *buf_date, char *format, int size) { time_t t; time(&t); strftime(buf_date, size, format, localtime(&t)); return buf_date; } Ecrit la chaine reçu en *data, dans le fichier spécifié dans *filename, dans le dossier *path : void write_char(char *mode, char *data, char *path, char *filename) { FILE * file; char full_path[PATH_MAX]; int writecount; snprintf(full_path,PATH_MAX,"%s/%s",path,filename); file = fopen(full_path,mode); if(file == NULL) { perror(full_path); } writecount = fprintf(file, "%s\n", data); if(writecount<0){ perror(full_path); } if ( fclose(file) != 0) { perror(full_path); } } |
home >