#include #include #include "ostool.h" #include "commun.h" /* Cr‚ation d'un r‚pertoire et des ses ancetres si requis Si le r‚pertoire existe d‚j… c'est ok doit etre sur le disque courant Retourne -1 si erreur */ export int file_mkdiranc (const char *path) { int ret = -1; int type = file_type (path); if (type == -1){ ret = file_mkdir(path); if (ret ==-1){ char anc[MAXSIZ_PATH]; path_splitlex(path,anc,NULL); if (anc[0] == '\0' || file_mkdiranc(anc) != -1){ ret = file_mkdir(path); } } }else if (type == 1){ // Le r‚pertoire existe, c'est ok // Si type != -1 et type != 1, c'est un fichier et ret == -1 ret = 0; } return ret; } #ifdef TEST static void test (const char *path) { printf ("detruit %s -> %d\n",path,file_unlink(path)); } void main (void) { printf ("mkdir /tmp/toto -> %d\n",file_mkdir ("/tmp/toto")); printf ("mkdir /tmp/toto1 -> %d\n",file_mkdir ("/tmp/toto1")); printf ("rmdir /tmp/toto1 -> %d\n",file_rmdir ("/tmp/toto1")); printf ("mkdir /tmp/x/y/z -> %d\n",file_mkdiranc ("/tmp/x/y/z")); system ("sh"); file_rmdir ("/tmp/x/y/z"); file_rmdir ("/tmp/x/y"); file_rmdir ("/tmp/x"); file_rmdir ("/tmp/toto"); #if 0 test ("*.bak"); test ("/usr/prj1/tool/*.obt"); #endif } #endif