]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/groff/libgroff/getcwd.c
This commit was generated by cvs2svn to compensate for changes in r52894,
[FreeBSD/FreeBSD.git] / contrib / groff / libgroff / getcwd.c
1 /* Partial emulation of getcwd in terms of getwd. */
2
3 #include <sys/param.h>
4 #include <string.h>
5 #include <errno.h>
6 #ifndef errno
7 extern int errno;
8 #endif
9
10 char *getwd();
11
12 char *getcwd(buf, size)
13      char *buf;
14      int size;                  /* POSIX says this should be size_t */
15 {
16   if (size <= 0) {
17     errno = EINVAL;
18     return 0;
19   }
20   else {
21     char mybuf[MAXPATHLEN];
22     int saved_errno = errno;
23
24     errno = 0;
25     if (!getwd(mybuf)) {
26       if (errno == 0)
27         ;       /* what to do? */
28       return 0;
29     }
30     errno = saved_errno;
31     if (strlen(mybuf) + 1 > size) {
32       errno = ERANGE;
33       return 0;
34     }
35     strcpy(buf, mybuf);
36     return buf;
37   }
38 }