aboutsummaryrefslogtreecommitdiffstats
path: root/ports/unix/guts/glob.c
blob: 0012179302543c216bf55cfd5488826b05f4899a (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
/* 
 * Copyright (c) 2010 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * static int
 * wrap_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) {
 *	int rc = -1;
 */
	char *rpattern = NULL;
	int alloced = 0;

	/* note:  no canonicalization */
	if (pattern && (*pattern == '/') && pseudo_chroot_len) {
		size_t len = strlen(pattern) + pseudo_chroot_len + 2;
		rpattern = malloc(len);
		if (!rpattern) {
			errno = ENOMEM;
			return GLOB_NOSPACE;
		}
		snprintf(rpattern, len, "%s/%s", pseudo_chroot, pattern);
		alloced = 1;
	}

	rc = real_glob(alloced ? rpattern : pattern, flags, errfunc, pglob);

	free(rpattern);

	if (rc == 0) {
		unsigned int i;
		for (i = 0; i < pglob->gl_pathc; ++i) {
			pseudo_dechroot(pglob->gl_pathv[i], (size_t) -1);
		}
	}
/*	return rc;
 * }
 */