2 /* Two PD getcwd() implementations.
3 Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */
10 /* Version for BSD systems -- use getwd() */
12 #ifdef HAVE_SYS_PARAM_H
13 #include <sys/param.h>
17 #if defined(PATH_MAX) && PATH_MAX > 1024
18 #define MAXPATHLEN PATH_MAX
20 #define MAXPATHLEN 1024
24 extern char *getwd(char *);
27 getcwd(char *buf
, int size
)
29 char localbuf
[MAXPATHLEN
+1];
36 ret
= getwd(localbuf
);
37 if (ret
!= NULL
&& strlen(localbuf
) >= (size_t)size
) {
42 errno
= EACCES
; /* Most likely error */
45 strncpy(buf
, localbuf
, size
);
49 #else /* !HAVE_GETWD */
51 /* Version for really old UNIX systems -- use pipe from pwd */
54 #define PWD_CMD "/bin/pwd"
58 getcwd(char *buf
, int size
)
67 if ((fp
= popen(PWD_CMD
, "r")) == NULL
)
69 if (fgets(buf
, size
, fp
) == NULL
|| (sts
= pclose(fp
)) != 0) {
70 errno
= EACCES
; /* Most likely error */
73 for (p
= buf
; *p
!= '\n'; p
++) {
83 #endif /* !HAVE_GETWD */