home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c019 / 1.ddi / ARC521_C / GETWD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  787 b   |  56 lines

  1. /*
  2.  * 4.2bsd getwd simulation for Sys V.3
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. #define SYSV3
  8.  
  9. #define MAXWD 1024         /* limited by 4.2 getwd(2) */
  10.  
  11. #ifdef SYSV3
  12.  
  13. char *getcwd();
  14.  
  15. char *
  16. getwd(path)
  17. char *path;
  18. {
  19.     return(getcwd(path,MAXWD));
  20. }
  21.  
  22. #else
  23.  
  24. /*
  25.  * 4.2bsd getwd simulation for Sys V.2
  26.  */
  27.  
  28. #include <stdio.h>
  29.  
  30. #define MAXWD 1024         /* limited by 4.2 getwd(2) */
  31.  
  32. char *
  33. getwd(path)
  34. char *path;
  35. {
  36.      char *nlp;
  37.      FILE *fp;
  38.      FILE *popen();
  39.      char *strrchr();
  40.  
  41.     putenv("IFS= \t\n");
  42.      fp = popen("PATH=/bin:/usr/bin pwd", "r");
  43.      if (fp == NULL)
  44.          return 0;
  45.      if (fgets(path, MAXWD, fp) == NULL) {
  46.          (void) pclose(fp);
  47.          return 0;
  48.      }
  49.      if ((nlp = strrchr(path, '\n')) != NULL)
  50.          *nlp = '\0';
  51.      (void) pclose(fp);
  52.      return path;
  53. }
  54. #endif
  55.  
  56.