Mercurial > cpython-lru_cache-weakref
annotate Python/getcwd.c @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +0100 |
| parents | f197407bdba2 |
| children | b36cb4602e21 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
144
diff
changeset
|
1 |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
2 /* Two PD getcwd() implementations. |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
3 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
|
4 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
5 #include <stdio.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
6 #include <errno.h> |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
7 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
8 #ifdef HAVE_GETWD |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
9 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
10 /* 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
|
11 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
12 #ifdef HAVE_SYS_PARAM_H |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
13 #include <sys/param.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
14 #endif |
| 116 | 15 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
16 #ifndef MAXPATHLEN |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
14375
diff
changeset
|
17 #if defined(PATH_MAX) && PATH_MAX > 1024 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
14375
diff
changeset
|
18 #define MAXPATHLEN PATH_MAX |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
14375
diff
changeset
|
19 #else |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
20 #define MAXPATHLEN 1024 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
21 #endif |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
14375
diff
changeset
|
22 #endif |
| 116 | 23 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
24 extern char *getwd(char *); |
| 116 | 25 |
| 26 char * | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
27 getcwd(char *buf, int size) |
| 116 | 28 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
29 char localbuf[MAXPATHLEN+1]; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
30 char *ret; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
31 |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
32 if (size <= 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
33 errno = EINVAL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
34 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
35 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
36 ret = getwd(localbuf); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
37 if (ret != NULL && strlen(localbuf) >= (size_t)size) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
38 errno = ERANGE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
39 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
40 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
41 if (ret == NULL) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
42 errno = EACCES; /* Most likely error */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
43 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
44 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
45 strncpy(buf, localbuf, size); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
46 return buf; |
| 116 | 47 } |
| 48 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
49 #else /* !HAVE_GETWD */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
50 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
51 /* 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
|
52 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
53 #ifndef PWD_CMD |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
54 #define PWD_CMD "/bin/pwd" |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
55 #endif |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
56 |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
57 char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
58 getcwd(char *buf, int size) |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
59 { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
60 FILE *fp; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
61 char *p; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
62 int sts; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
63 if (size <= 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
64 errno = EINVAL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
65 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
66 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
67 if ((fp = popen(PWD_CMD, "r")) == NULL) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
68 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
69 if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
70 errno = EACCES; /* Most likely error */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
71 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
72 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
73 for (p = buf; *p != '\n'; p++) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
74 if (*p == '\0') { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
75 errno = ERANGE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
76 return NULL; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
77 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
78 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
79 *p = '\0'; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
38453
diff
changeset
|
80 return buf; |
|
144
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
81 } |
|
c70eefe48029
Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents:
116
diff
changeset
|
82 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
83 #endif /* !HAVE_GETWD */ |
