Mercurial > cpython-lru_cache-weakref
annotate Python/getcwd.c @ 1257:1cabc2b6c970 legacy-trunk
* Changed all copyright messages to include 1993.
* Stubs for faster implementation of local variables (not yet finished)
* Added function name to code object. Print it for code and function
objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version
number has changed accordingly)
* Print address of self for built-in methods
* New internal functions getattro and setattro (getattr/setattr with
string object arg)
* Replaced "dictobject" with more powerful "mappingobject"
* New per-type functio tp_hash to implement arbitrary object hashing,
and hashobject() to interface to it
* Added built-in functions hash(v) and hasattr(v, 'name')
* classobject: made some functions static that accidentally weren't;
added __hash__ special instance method to implement hash()
* Added proper comparison for built-in methods and functions
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Mar 1993 10:43:31 +0000 |
| parents | 0cd197947d81 |
| children | cd397266dc1c |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
1 /*********************************************************** |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
3 Amsterdam, 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 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
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 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
12 Centrum or CWI not be used in advertising or publicity pertaining to |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
13 distribution of the software without specific, written prior permission. |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
14 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
22 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
23 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
24 |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
25 /* Two PD getcwd() implementations. |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
26 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
|
27 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
28 /* #define NO_GETWD /* Turn this on to popen pwd instead of calling getwd() */ |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
29 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
30 #include <stdio.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
31 #include <errno.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
32 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
33 extern int errno; |
|
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 #ifndef NO_GETWD |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
36 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
37 /* Default: Version for BSD systems -- use getwd() */ |
| 116 | 38 |
| 39 #include "sys/param.h" | |
| 40 | |
| 41 extern char *getwd(); | |
| 42 | |
| 43 char * | |
| 44 getcwd(buf, size) | |
| 45 char *buf; | |
| 46 int size; | |
| 47 { | |
| 48 char localbuf[MAXPATHLEN+1]; | |
| 49 char *ret; | |
| 50 | |
| 51 if (size <= 0) { | |
| 52 errno = EINVAL; | |
| 53 return NULL; | |
| 54 } | |
| 55 ret = getwd(localbuf); | |
| 56 if (ret != NULL && strlen(localbuf) >= size) { | |
| 57 errno = ERANGE; | |
| 58 return NULL; | |
| 59 } | |
| 60 if (ret == NULL) { | |
| 61 errno = EACCES; /* Most likely error */ | |
| 62 return NULL; | |
| 63 } | |
| 64 strncpy(buf, localbuf, size); | |
| 65 return buf; | |
| 66 } | |
| 67 | |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
68 #else |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
69 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
70 /* NO_GETWD defined: Version for backward UNIXes -- popen /bin/pwd */ |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
71 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
72 #define PWD_CMD "/bin/pwd" |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
73 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
74 char * |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
75 getcwd(buf, size) |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
76 char *buf; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
77 int size; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
78 { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
79 FILE *fp; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
80 char *p; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
81 int sts; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
82 if (size <= 0) { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
83 errno = EINVAL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
84 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
85 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
86 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
|
87 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
88 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
|
89 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
|
90 return NULL; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
91 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
92 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
|
93 if (*p == '\0') { |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
94 errno = ERANGE; |
|
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 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
98 *p = '\0'; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
99 return buf; |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
100 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
101 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
102 #endif |
