aboutsummaryrefslogtreecommitdiffstats
path: root/ports/unix/guts/realpath.c
blob: 8d8118b9e79e958d3987cf4ed2da5f282cd1c7aa (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
/* 
 * Copyright (c) 2010 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * SPDX-License-Identifier: LGPL-2.1-only
 *
 * static char *
 * wrap_realpath(const char *name, char *resolved_name) {
 *	char * rc = NULL;
 */
	char *rname = PSEUDO_ROOT_PATH(AT_FDCWD, name, 0);
	ssize_t len;
	if (!rname) {
		errno = ENAMETOOLONG;
		return NULL;
	}
		len = strlen(rname);
		char *ep = rname + len - 1;
		while (ep > rname && *ep == '/') {
			--len;
			*(ep--) = '\0';
		}

		if (len >= pseudo_sys_path_max()) {
		errno = ENAMETOOLONG;
		return NULL;
	}
	if (resolved_name) {
		memcpy(resolved_name, rname, len + 1);
		rc = resolved_name;
	} else {
		rc = strdup(rname);
	}

/*	return rc;
 * }
 */