blob: 208e8111853095fd0ba8ece9ed63b99644964326 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/* Partial emulation of getcwd in terms of getwd. */
#include <sys/param.h>
#include <string.h>
#include <errno.h>
#ifndef errno
extern int errno;
#endif
char *getwd();
char *getcwd(buf, size)
char *buf;
int size; /* POSIX says this should be size_t */
{
if (size <= 0) {
errno = EINVAL;
return 0;
}
else {
char mybuf[MAXPATHLEN];
int saved_errno = errno;
errno = 0;
if (!getwd(mybuf)) {
if (errno == 0)
; /* what to do? */
return 0;
}
errno = saved_errno;
if (strlen(mybuf) + 1 > size) {
errno = ERANGE;
return 0;
}
strcpy(buf, mybuf);
return buf;
}
}
|