Mercurial > cpython-lru_cache-weakref
annotate Python/getcwd.c @ 10072:ecebcd84df37 legacy-trunk
put the preferences file in a folder called "Python" inside the prefs folder, just like the IDE does -- jvr
| author | Just van Rossum <just@lettererror.com> |
|---|---|
| date | Tue, 02 Feb 1999 15:49:03 +0000 |
| parents | 65d2d8e67da3 |
| children | 8c8de5b736dc |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
4 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
5 All Rights Reserved |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
15 permission. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
29 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
30 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
31 |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
32 /* Two PD getcwd() implementations. |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
33 Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */ |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
34 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
35 #include <stdio.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
36 #include <errno.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
37 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
38 #ifdef HAVE_GETWD |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
39 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
40 /* Version for BSD systems -- use getwd() */ |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
41 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
42 #ifdef HAVE_SYS_PARAM_H |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
43 #include <sys/param.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
44 #endif |
| 116 | 45 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
46 #ifndef MAXPATHLEN |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
47 #define MAXPATHLEN 1024 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
48 #endif |
| 116 | 49 |
| 50 extern char *getwd(); | |
| 51 | |
| 52 char * | |
| 53 getcwd(buf, size) | |
| 54 char *buf; | |
| 55 int size; | |
| 56 { | |
| 57 char localbuf[MAXPATHLEN+1]; | |
| 58 char *ret; | |
| 59 | |
| 60 if (size <= 0) { | |
| 61 errno = EINVAL; | |
| 62 return NULL; | |
| 63 } | |
| 64 ret = getwd(localbuf); | |
| 65 if (ret != NULL && strlen(localbuf) >= size) { | |
| 66 errno = ERANGE; | |
| 67 return NULL; | |
| 68 } | |
| 69 if (ret == NULL) { | |
| 70 errno = EACCES; /* Most likely error */ | |
| 71 return NULL; | |
| 72 } | |
| 73 strncpy(buf, localbuf, size); | |
| 74 return buf; | |
| 75 } | |
| 76 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
77 #else /* !HAVE_GETWD */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
78 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
79 /* Version for really old UNIX systems -- use pipe from pwd */ |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
80 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
81 #ifndef PWD_CMD |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
82 #define PWD_CMD "/bin/pwd" |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
83 #endif |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
84 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
85 char * |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
86 getcwd(buf, size) |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
87 char *buf; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
88 int size; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
89 { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
90 FILE *fp; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
91 char *p; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
92 int sts; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
93 if (size <= 0) { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
94 errno = EINVAL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
95 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
96 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
97 if ((fp = popen(PWD_CMD, "r")) == NULL) |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
98 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
99 if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
100 errno = EACCES; /* Most likely error */ |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
101 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
102 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
103 for (p = buf; *p != '\n'; p++) { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
104 if (*p == '\0') { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
105 errno = ERANGE; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
106 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
107 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
108 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
109 *p = '\0'; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
110 return buf; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
111 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
112 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
113 #endif /* !HAVE_GETWD */ |
