mailing list of musl libc
 help / color / mirror / code / Atom feed
306dbc4f184d851d2a5803b33f183adbfce85697 blob 814 bytes (raw)

 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
39
40
41
42
43
44
45
46
47
48
49
50
 
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include "syscall.h"
#include "libc.h"

static char *do_getcwd(char *buf, size_t size)
{
	long ret = syscall(SYS_getcwd, buf, size);
	if (ret < 0)
		return 0;
	if (ret == 0 || buf[0] != '/') {
		errno = ENOENT;
		return 0;
	}
	return buf;
}

static char *getcwd_glibc(size_t size)
{
	char tmp[PATH_MAX];
	if (!do_getcwd(tmp, sizeof tmp))
		return 0;
	size_t len = strlen(tmp) + 1;
	if (!size)
		size = len;
	else if (size < len) {
		errno = ERANGE;
		return 0;
	}
	char *buf = malloc(size);
	if (!buf) {
		errno = ENOMEM;
		return 0;
	}
	memcpy(buf, tmp, len);
	return buf;
}

char *getcwd(char *buf, size_t size)
{
	if (!buf)
		return getcwd_glibc(size);
	if (!size) {
		errno = EINVAL;
		return 0;
	}
	return do_getcwd(buf, size);
}
debug log:

solving 306dbc4f ...
found 306dbc4f in https://inbox.vuxu.org/musl/CAEg67GmbDfovHHUUXzvZL6CLZOZBssZox4fD9+wQLdiEzHW5_w@mail.gmail.com/
found 103fbbb5 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 103fbbb5f78f1fc3578d1ed3839f6667f3ddef87	src/unistd/getcwd.c

applying [1/1] https://inbox.vuxu.org/musl/CAEg67GmbDfovHHUUXzvZL6CLZOZBssZox4fD9+wQLdiEzHW5_w@mail.gmail.com/
diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c
index 103fbbb5..306dbc4f 100644

Checking patch src/unistd/getcwd.c...
Applied patch src/unistd/getcwd.c cleanly.

index at:
100644 306dbc4f184d851d2a5803b33f183adbfce85697	src/unistd/getcwd.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).