home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN321SRC.ZIP / oslnxful.c < prev    next >
C/C++ Source or Header  |  2004-07-16  |  1KB  |  44 lines

  1. /* $Id: oslnxful.c,v 1.4 2004/07/15 17:44:02 ozzmosis Exp $ */
  2.  
  3. #define HAVE_OS_FULLPATH
  4. #include <unistd.h>
  5.  
  6. #ifdef DMALLOC
  7. #include "dmalloc.h"
  8. #endif
  9.  
  10. int os_fullpath(char *dst, const char *src, size_t bufsize)
  11. {
  12.     char olddir[MYMAXDIR];
  13.     char dir[MYMAXDIR];
  14.     char name[MYMAXFILE];
  15.     char ext[MYMAXEXT];
  16.  
  17.     myfnsplit(src, NULL, dir, name, ext);
  18. #define FUNCNAME ""
  19.     Debug1("[linux] os_fullpath: dir=%s", dir);
  20.     Debug1(" name=%s", name);
  21.     Debug1(" ext=%s\n", ext);
  22.     getcwd(olddir, sizeof olddir);
  23. #undef FUNCNAME
  24. #define FUNCNAME "[linux] os_fullpath"
  25.     Debug1("old directory=%s\n", olddir);
  26.     if (dir[0] && chdir(dir) == -1)
  27.     {
  28.         Debug1("change directory to '%s' failed!\n", dir);
  29.         return -1;
  30.     }
  31.     if (getcwd(dir, MYMAXDIR) == NULL
  32.         || strlen(dir) + strlen(name) + strlen(ext) > bufsize)
  33.     {
  34.         fprintf(stderr, "Directory name for %s too long!\n", src);
  35.         chdir(olddir);
  36.         return -1;
  37.     }
  38.     myfnmerge(dst, NULL, dir, name, ext);
  39.     Debug1("Complete filename: %s\n", dst);
  40.     chdir(olddir);
  41.     return 0;
  42. #undef FUNCNAME
  43. }
  44.