1993-07-15 20:34:49 +04:00
|
|
|
/* Partial emulation of getcwd in terms of getwd. */
|
|
|
|
|
1993-08-02 21:38:43 +04:00
|
|
|
#ifndef lint
|
|
|
|
static char rcsid[] = "$Id: getcwd.c,v 1.2 1993/08/02 17:44:02 mycroft Exp $";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
1993-07-15 20:34:49 +04:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|