#include #include #include #include #include "vfs.h" #include #ifdef TEST #define testprt(x) printf(x) #else #define testprt(x) #endif /* Obtient repertoire courant Retourne -1 si trop long ou erreur, 0 si ok */ int path_getcwd (char *path,int buflen) { #if 1 strncpy (path,_dispatch_getcwd(),buflen); return 0; #else int ok = -1; FILEINFO info; static int lastinode=-1; static int lastdevice=-1; static char lastpath[PATH_MAX]; file_statinfo (".",&info); if (info.inode != lastinode || info.device != lastdevice){ testprt ("Appelle getcwd\n"); if (getcwd(path,buflen) != NULL){ strcpy (lastpath,path); lastinode = info.inode; lastdevice = info.device; ok = 0; } }else if ((int)strlen(lastpath)path,PATH_MAX) != 0 || path_chdir (path) != 0){ ok = -1; } return (ok); } /* Annule l'effet de path_pushdir en revenant au r‚pertoire de d‚part Change de disque aussi Retourne -1 si erreur, 0 si ok */ int path_popdir (SAVEPATH *savepath) { int ok = 0; if (path_chdir (savepath->path)==-1) ok = -1; return (ok); } #ifdef TEST static void show (void) { char buf[PATH_MAX]; int i; for (i=0; i<3; i++) path_getcwd (buf,sizeof(buf)-1); printf ("cwd = %s\n",buf); } static void tstmak (const char *base) { char fp[PATH_MAX]; path_make (base,"toto",fp); printf ("base :%s: + toto -> :%s:\n",base,fp); } int main (int, char *argv[]) { SAVEPATH save; tstmak (""); tstmak ("."); tstmak (".."); tstmak ("../h"); tstmak ("../../h"); path_pushdir ("/home/solucor/jack",&save); show (); path_popdir (&save); show (); path_chdir ("/usr/include"); show (); path_chdir ("/home/solucor/jack/prj/tool"); show (); path_chdir ("/"); show (); } #endif