annotate Python/getcwd.c @ 56121:ea697cde6882 3.1

Merged revisions 74881-74885,74888,74891-74895,74900,74905-74906,74931-74932,74934,74941-74942,74944,74956 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74881 | r.david.murray | 2009-09-17 15:12:49 -0400 (Thu, 17 Sep 2009) | 2 lines Check in first draft of maintainers.rst. ........ r74882 | eric.smith | 2009-09-17 15:22:30 -0400 (Thu, 17 Sep 2009) | 1 line Typo. ........ r74883 | mark.dickinson | 2009-09-17 15:37:28 -0400 (Thu, 17 Sep 2009) | 1 line Add some more module maintainers. ........ r74884 | mark.dickinson | 2009-09-17 15:39:12 -0400 (Thu, 17 Sep 2009) | 1 line Revert accidental changes to Objects/longobject.c ........ r74885 | mark.dickinson | 2009-09-17 16:20:01 -0400 (Thu, 17 Sep 2009) | 1 line Add decimal maintainers ........ r74888 | r.david.murray | 2009-09-17 18:10:48 -0400 (Thu, 17 Sep 2009) | 2 lines Maintainer additions from MAL. ........ r74891 | georg.brandl | 2009-09-17 18:18:01 -0400 (Thu, 17 Sep 2009) | 1 line Some more maintainers. ........ r74892 | r.david.murray | 2009-09-17 19:23:56 -0400 (Thu, 17 Sep 2009) | 2 lines Add a couple interest areas for Nick per his request. ........ r74893 | r.david.murray | 2009-09-17 19:43:20 -0400 (Thu, 17 Sep 2009) | 2 lines Benajmin is also compiler-knowledgeable. ........ r74894 | alexandre.vassalotti | 2009-09-17 20:59:05 -0400 (Thu, 17 Sep 2009) | 2 lines Added myself to my areas of interest. ........ r74895 | brett.cannon | 2009-09-17 21:03:35 -0400 (Thu, 17 Sep 2009) | 1 line Add myself to a couple places as maintainer. ........ r74900 | georg.brandl | 2009-09-18 05:06:37 -0400 (Fri, 18 Sep 2009) | 1 line Add myself in interest areas. ........ r74905 | ezio.melotti | 2009-09-18 05:58:43 -0400 (Fri, 18 Sep 2009) | 1 line Add myself in interest areas and mark effbot as inactive in winsound ........ r74906 | antoine.pitrou | 2009-09-18 09:15:23 -0400 (Fri, 18 Sep 2009) | 3 lines Add myself in a couple of places ........ r74931 | r.david.murray | 2009-09-18 17:25:36 -0400 (Fri, 18 Sep 2009) | 5 lines Add some names gleaned from the "Tracker Archeology" thread on python-dev from back in February. Also consolidate the autoconf and makefiles topics into one, and add tracker and svn/hg topics. ........ r74932 | r.david.murray | 2009-09-18 17:32:16 -0400 (Fri, 18 Sep 2009) | 2 lines Remove non-committer mistakenly added. ........ r74934 | r.david.murray | 2009-09-18 17:40:30 -0400 (Fri, 18 Sep 2009) | 2 lines More descriptive/generic name for the svn/hg entry (version control) ........ r74941 | benjamin.peterson | 2009-09-18 18:45:59 -0400 (Fri, 18 Sep 2009) | 1 line add a new category for myself ........ r74942 | benjamin.peterson | 2009-09-18 18:50:55 -0400 (Fri, 18 Sep 2009) | 1 line add myself for symtable ........ r74944 | georg.brandl | 2009-09-19 03:39:05 -0400 (Sat, 19 Sep 2009) | 1 line I would like to maintain the token module! ........ r74956 | r.david.murray | 2009-09-19 14:40:08 -0400 (Sat, 19 Sep 2009) | 3 lines Add everyone who we know has been a release manager as a resource for the 'release management' topic. ........
author R. David Murray <rdmurray@bitdance.com>
date Sat, 19 Sep 2009 19:04:37 +0000
parents 29ae5e0fc348
children e38335d4df91 5cea27275af1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 {
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 char localbuf[MAXPATHLEN+1];
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 char *ret;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 if (size <= 0) {
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 errno = EINVAL;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 return NULL;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 }
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 ret = getwd(localbuf);
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
37 if (ret != NULL && strlen(localbuf) >= (size_t)size) {
116
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 errno = ERANGE;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 return NULL;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 }
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 if (ret == NULL) {
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 errno = EACCES; /* Most likely error */
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 return NULL;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 }
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 strncpy(buf, localbuf, size);
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 return buf;
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 }
0a02ca9dcd6e Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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 {
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
60 FILE *fp;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
61 char *p;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
62 int sts;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
63 if (size <= 0) {
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
64 errno = EINVAL;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
65 return NULL;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
66 }
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
67 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
68 return NULL;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
69 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
70 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
71 return NULL;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
72 }
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
73 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
74 if (*p == '\0') {
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
75 errno = ERANGE;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
76 return NULL;
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
77 }
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 *p = '\0';
c70eefe48029 Added version that opens a pipe to /bin/pwd.
Guido van Rossum <guido@python.org>
parents: 116
diff changeset
80 return buf;
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 */