OSDN Git Service

60c1dd84eed984cc4612db8c9398b2331c1f04f1
[pf3gnuchains/gcc-fork.git] / libiberty / getcwd.c
1 /* Emulate getcwd using getwd.
2    This function is in the public domain. */
3
4 /*
5 NAME
6         getcwd -- get absolute pathname for current working directory
7
8 SYNOPSIS
9         char *getcwd (char pathname[len], len)
10
11 DESCRIPTION
12         Copy the absolute pathname for the current working directory into
13         the supplied buffer and return a pointer to the buffer.  If the 
14         current directory's path doesn't fit in LEN characters, the result
15         is NULL and errno is set.
16
17 BUGS
18         Emulated via the getwd() call, which is reasonable for most
19         systems that do not have getcwd().
20
21 */
22
23 #ifndef NO_SYS_PARAM_H
24 #include <sys/param.h>
25 #endif
26 #include <errno.h>
27
28 extern char *getwd ();
29 extern int errno;
30
31 #ifndef MAXPATHLEN
32 #define MAXPATHLEN 1024
33 #endif
34
35 char *
36 getcwd (buf, len)
37   char *buf;
38   int len;
39 {
40   char ourbuf[MAXPATHLEN];
41   char *result;
42
43   result = getwd (ourbuf);
44   if (result) {
45     if (strlen (ourbuf) >= len) {
46       errno = ERANGE;
47       return 0;
48     }
49     strcpy (buf, ourbuf);
50   }
51   return buf;
52 }