Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
a9f5a65c
Commit
a9f5a65c
authored
Aug 20, 1992
by
Richard Stallman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial revision
From-SVN: r1911
parent
e6fe56a4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
gcc/getpwd.c
+92
-0
No files found.
gcc/getpwd.c
0 → 100644
View file @
a9f5a65c
/* getpwd.c - get the working directory */
#include "config.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef errno
extern
int
errno
;
#endif
/* Virtually every UN*X system now in common use (except for pre-4.3-tahoe
BSD systems) now provides getcwd as called for by POSIX. Allow for
the few exceptions to the general rule here. */
#if !(defined (POSIX) || defined (USG) || defined (VMS))
#include <sys/param.h>
extern
char
*
getwd
();
#define getcwd(buf,len) getwd(buf)
#define GUESSPATHLEN (MAXPATHLEN + 1)
#else
/* (defined (USG) || defined (VMS)) */
extern
char
*
getcwd
();
/* We actually use this as a starting point, not a limit. */
#define GUESSPATHLEN 100
#endif
/* (defined (USG) || defined (VMS)) */
char
*
getenv
();
char
*
xmalloc
();
#ifndef VMS
/* Get the working directory. Use the PWD environment variable if it's
set correctly, since this is faster and gives more uniform answers
to the user. Yield the working directory if successful; otherwise,
yield 0 and set errno. */
char
*
getpwd
()
{
static
char
*
pwd
;
static
int
failure_errno
;
char
*
p
=
pwd
;
size_t
s
;
struct
stat
dotstat
,
pwdstat
;
if
(
!
p
&&
!
(
errno
=
failure_errno
))
{
if
(
!
((
p
=
getenv
(
"PWD"
))
!=
0
&&
*
p
==
'/'
&&
stat
(
p
,
&
pwdstat
)
==
0
&&
stat
(
"."
,
&
dotstat
)
==
0
&&
dotstat
.
st_ino
==
pwdstat
.
st_ino
&&
dotstat
.
st_dev
==
pwdstat
.
st_dev
))
/* The shortcut didn't work. Try the slow, ``sure'' way. */
for
(
s
=
GUESSPATHLEN
;
!
getcwd
(
p
=
xmalloc
(
s
),
s
);
s
*=
2
)
{
int
e
=
errno
;
free
(
p
);
if
(
e
!=
ERANGE
)
{
errno
=
failure_errno
=
e
;
p
=
0
;
break
;
}
}
/* Cache the result. This assumes that the program does
not invoke chdir between calls to getpwd. */
pwd
=
p
;
}
return
p
;
}
#else
/* VMS */
#ifndef MAXPATHLEN
#define MAXPATHLEN 255
#endif
char
*
getpwd
()
{
static
char
*
pwd
=
0
;
if
(
!
pwd
)
pwd
=
getcwd
(
xmalloc
(
MAXPATHLEN
+
1
),
MAXPATHLEN
+
1
);
return
pwd
;
}
#endif
/* VMS */
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