]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - libiberty/getcwd.c
This commit was generated by cvs2svn to track changes on a CVS vendor
[thirdparty/binutils-gdb.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 #include "config.h"
24
25 #ifdef HAVE_SYS_PARAM_H
26 #include <sys/param.h>
27 #endif
28 #include <errno.h>
29
30 extern char *getwd ();
31 extern int errno;
32
33 #ifndef MAXPATHLEN
34 #define MAXPATHLEN 1024
35 #endif
36
37 char *
38 getcwd (buf, len)
39 char *buf;
40 int len;
41 {
42 char ourbuf[MAXPATHLEN];
43 char *result;
44
45 result = getwd (ourbuf);
46 if (result) {
47 if (strlen (ourbuf) >= len) {
48 errno = ERANGE;
49 return 0;
50 }
51 strcpy (buf, ourbuf);
52 }
53 return buf;
54 }