blob: ff919a9d21e4b9678a98febc2edcc6bd2b82e93f [file] [log] [blame] [raw]
#include <stdio.h>
#include <errno.h>
#include <string.h>
#if 1
char *strerror_r(int, char *, size_t);
#endif
char *getcwd(char *buf, size_t size) {
if(size == 0) {
if(buf) {
errno = EINVAL;
return NULL;
}
//char *path = malloc(2 * sizeof(char));
//path[0] = '/';
//path[1] = '\0';
//return path;
buf = malloc(2 * sizeof(char));
} else if(size < 2) {
errno = ERANGE;
return NULL;
}
buf[0] = '/';
buf[1] = 0;
return buf;
}
char *getwd(char *buf) {
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
char tmpbuf[PATH_MAX];
if(!buf){
errno = EINVAL;
return NULL;
}
if(!getcwd(tmpbuf, PATH_MAX)) {
strerror_r(errno, buf, 1024);
return NULL;
}
/* This is completely unsafe. Nobody can say how big the user
provided buffer is. Perhaps the application and the libc
disagree about the value of PATH_MAX. */
return strcpy(buf, tmpbuf);
}