Exemple #1
0
char *getcwd(char *buf, int size)
{
    int ret;
    char *path;
    size_t alloc_size = size;

    if (size == 0) {
	if (buf != NULL) {
	    __set_errno(EINVAL);
	    return NULL;
	}
	alloc_size = PATH_MAX;
    }
    path=buf;
    if (buf == NULL) {
	path = malloc(alloc_size);
	if (path == NULL)
	    return NULL;
    }
    ret = __syscall_getcwd(path, alloc_size);
    if (ret >= 0)
    {
	if (buf == NULL && size == 0)
	    buf = realloc(path, ret);
	if (buf == NULL)
	    buf = path;
	return buf;
    }
    if (buf == NULL)
	free (path);
    return NULL;
}
Exemple #2
0
char *getcwd(char *buf, size_t size) {
  int tmp;
  if ((tmp = __syscall_getcwd(buf, size)) < 0)
    return 0;
  buf[tmp] = 0;
  return buf;
}