1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Two PD getcwd() implementations.
26 Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */
33 /* Version for BSD systems -- use getwd() */
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
40 #define MAXPATHLEN 1024
50 char localbuf
[MAXPATHLEN
+1];
57 ret
= getwd(localbuf
);
58 if (ret
!= NULL
&& strlen(localbuf
) >= size
) {
63 errno
= EACCES
; /* Most likely error */
66 strncpy(buf
, localbuf
, size
);
70 #else /* !HAVE_GETWD */
72 /* Version for really old UNIX systems -- use pipe from pwd */
75 #define PWD_CMD "/bin/pwd"
90 if ((fp
= popen(PWD_CMD
, "r")) == NULL
)
92 if (fgets(buf
, size
, fp
) == NULL
|| (sts
= pclose(fp
)) != 0) {
93 errno
= EACCES
; /* Most likely error */
96 for (p
= buf
; *p
!= '\n'; p
++) {
106 #endif /* !HAVE_GETWD */