Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
32c7d1b8
Commit
32c7d1b8
authored
Feb 19, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added version that opens a pipe to /bin/pwd.
parent
7e6652cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
4 deletions
+47
-4
Python/getcwd.c
Python/getcwd.c
+47
-4
No files found.
Python/getcwd.c
View file @
32c7d1b8
/* Quick hack to get posix.getcwd() working for pure BSD 4.3 */
/* Two PD getcwd() implementations.
Author: Guido van Rossum, CWI Amsterdam, Jan 1991, <guido@cwi.nl>. */
#include "sys/param.h"
#include "errno.h"
/* #define NO_GETWD /* Turn this on to popen pwd instead of calling getwd() */
#include <stdio.h>
#include <errno.h>
extern
int
errno
;
#ifndef NO_GETWD
/* Default: Version for BSD systems -- use getwd() */
#include "sys/param.h"
extern
char
*
getwd
();
char
*
...
...
@@ -32,4 +41,38 @@ getcwd(buf, size)
return
buf
;
}
/* PS: for really old systems you must popen /bin/pwd ... */
#else
/* NO_GETWD defined: Version for backward UNIXes -- popen /bin/pwd */
#define PWD_CMD "/bin/pwd"
char
*
getcwd
(
buf
,
size
)
char
*
buf
;
int
size
;
{
FILE
*
fp
;
char
*
p
;
int
sts
;
if
(
size
<=
0
)
{
errno
=
EINVAL
;
return
NULL
;
}
if
((
fp
=
popen
(
PWD_CMD
,
"r"
))
==
NULL
)
return
NULL
;
if
(
fgets
(
buf
,
size
,
fp
)
==
NULL
||
(
sts
=
pclose
(
fp
))
!=
0
)
{
errno
=
EACCES
;
/* Most likely error */
return
NULL
;
}
for
(
p
=
buf
;
*
p
!=
'\n'
;
p
++
)
{
if
(
*
p
==
'\0'
)
{
errno
=
ERANGE
;
return
NULL
;
}
}
*
p
=
'\0'
;
return
buf
;
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment