|
|
1.1 root 1: /* Emulate getcwd using getwd.
2: Copyright 1991 Free Software Foundation, Inc.
3:
4: This file is part of the libiberty library.
5: Libiberty is free software; you can redistribute it and/or
6: modify it under the terms of the GNU Library General Public
7: License as published by the Free Software Foundation; either
8: version 2 of the License, or (at your option) any later version.
9:
10: Libiberty is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: Library General Public License for more details.
14:
15: You should have received a copy of the GNU Library General Public
16: License along with libiberty; see the file COPYING.LIB. If
17: not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18: Cambridge, MA 02139, USA. */
19:
20: /*
21:
22: NAME
23:
24: getcwd -- get absolute pathname for current working directory
25:
26: SYNOPSIS
27:
28: char *getcwd (char pathname[len], len)
29:
30: DESCRIPTION
31:
32: Copy the absolute pathname for the current working directory into
33: the supplied buffer and return a pointer to the buffer. If the
34: current directory's path doesn't fit in LEN characters, the result
35: is NULL and errno is set.
36:
37: BUGS
38:
39: Emulated via the getwd() call, which is reasonable for most
40: systems that do not have getcwd().
41:
42: */
43:
44: #include <sys/param.h>
45: #include <errno.h>
46:
47: extern char *getwd ();
48: extern int errno;
49:
50: #ifndef MAXPATHLEN
51: #define MAXPATHLEN 1024
52: #endif
53:
54: char *
55: getcwd (buf, len)
56: char *buf;
57: int len;
58: {
59: char ourbuf[MAXPATHLEN];
60: char *result;
61:
62: result = getwd (ourbuf);
63: if (result) {
64: if (strlen (ourbuf) >= len) {
65: errno = ERANGE;
66: return 0;
67: }
68: strcpy (buf, ourbuf);
69: }
70: return buf;
71: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.