2004-12-13 20:05:09 +01:00
|
|
|
/** $MirBSD: src/bin/ksh/path.c,v 2.2 2004/12/13 19:05:09 tg Exp $ */
|
2004-09-21 13:57:17 +02:00
|
|
|
/* $OpenBSD: path.c,v 1.9 2003/10/22 07:40:38 jmc Exp $ */
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
#include "sh.h"
|
|
|
|
#include "ksh_stat.h"
|
|
|
|
|
2004-12-13 20:05:09 +01:00
|
|
|
__RCSID("$MirBSD: src/bin/ksh/path.c,v 2.2 2004/12/13 19:05:09 tg Exp $");
|
2004-10-28 13:03:24 +02:00
|
|
|
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
/*
|
|
|
|
* Contains a routine to search a : separated list of
|
|
|
|
* paths (a la CDPATH) and make appropriate file names.
|
|
|
|
* Also contains a routine to simplify .'s and ..'s out of
|
|
|
|
* a path name.
|
|
|
|
*
|
|
|
|
* Larry Bouzane (larry@cs.mun.ca)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef S_ISLNK
|
2004-10-28 13:11:19 +02:00
|
|
|
static char *do_phys_path(XString *xsp, char *xp, const char *path);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
#endif /* S_ISLNK */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Makes a filename into result using the following algorithm.
|
|
|
|
* - make result NULL
|
|
|
|
* - if file starts with '/', append file to result & set cdpathp to NULL
|
|
|
|
* - if file starts with ./ or ../ append cwd and file to result
|
|
|
|
* and set cdpathp to NULL
|
|
|
|
* - if the first element of cdpathp doesnt start with a '/' xx or '.' xx
|
|
|
|
* then cwd is appended to result.
|
|
|
|
* - the first element of cdpathp is appended to result
|
|
|
|
* - file is appended to result
|
|
|
|
* - cdpathp is set to the start of the next element in cdpathp (or NULL
|
|
|
|
* if there are no more elements.
|
|
|
|
* The return value indicates whether a non-null element from cdpathp
|
2003-12-22 21:22:51 +01:00
|
|
|
* was appended to result.
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
*/
|
|
|
|
int
|
2004-10-28 13:53:44 +02:00
|
|
|
make_path(const char *cwd, const char *file, char **cdpathp, XString *xsp, int *phys_pathp)
|
|
|
|
|
|
|
|
|
|
|
|
/* & of : separated list */
|
|
|
|
|
|
|
|
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
int rval = 0;
|
|
|
|
int use_cdpath = 1;
|
|
|
|
char *plist;
|
|
|
|
int len;
|
|
|
|
int plen = 0;
|
|
|
|
char *xp = Xstring(*xsp, xp);
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
file = null;
|
|
|
|
|
|
|
|
if (!ISRELPATH(file)) {
|
|
|
|
*phys_pathp = 0;
|
|
|
|
use_cdpath = 0;
|
|
|
|
} else {
|
|
|
|
if (file[0] == '.') {
|
|
|
|
char c = file[1];
|
|
|
|
|
|
|
|
if (c == '.')
|
|
|
|
c = file[2];
|
|
|
|
if (ISDIRSEP(c) || c == '\0')
|
|
|
|
use_cdpath = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
plist = *cdpathp;
|
|
|
|
if (!plist)
|
|
|
|
use_cdpath = 0;
|
|
|
|
else if (use_cdpath) {
|
|
|
|
char *pend;
|
|
|
|
|
|
|
|
for (pend = plist; *pend && *pend != PATHSEP; pend++)
|
|
|
|
;
|
|
|
|
plen = pend - plist;
|
|
|
|
*cdpathp = *pend ? ++pend : (char *) 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((use_cdpath == 0 || !plen || ISRELPATH(plist))
|
|
|
|
&& (cwd && *cwd))
|
|
|
|
{
|
|
|
|
len = strlen(cwd);
|
|
|
|
XcheckN(*xsp, xp, len);
|
|
|
|
memcpy(xp, cwd, len);
|
|
|
|
xp += len;
|
|
|
|
if (!ISDIRSEP(cwd[len - 1]))
|
|
|
|
Xput(*xsp, xp, DIRSEP);
|
|
|
|
}
|
|
|
|
*phys_pathp = Xlength(*xsp, xp);
|
|
|
|
if (use_cdpath && plen) {
|
|
|
|
XcheckN(*xsp, xp, plen);
|
|
|
|
memcpy(xp, plist, plen);
|
|
|
|
xp += plen;
|
|
|
|
if (!ISDIRSEP(plist[plen - 1]))
|
|
|
|
Xput(*xsp, xp, DIRSEP);
|
|
|
|
rval = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(file) + 1;
|
|
|
|
XcheckN(*xsp, xp, len);
|
|
|
|
memcpy(xp, file, len);
|
|
|
|
|
|
|
|
if (!use_cdpath)
|
|
|
|
*cdpathp = (char *) 0;
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplify pathnames containing "." and ".." entries.
|
|
|
|
* ie, simplify_path("/a/b/c/./../d/..") returns "/a/b"
|
|
|
|
*/
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
simplify_path(char *path)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
char *cur;
|
|
|
|
char *t;
|
|
|
|
int isrooted;
|
|
|
|
char *very_start = path;
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((isrooted = ISROOTEDPATH(path)))
|
|
|
|
very_start++;
|
2004-12-13 20:05:09 +01:00
|
|
|
#if defined (__CYGWIN__)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
if (path[0] && path[1] == ':') /* skip a: */
|
|
|
|
very_start += 2;
|
2004-12-13 20:05:09 +01:00
|
|
|
#endif
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
/* Before After
|
|
|
|
* /foo/ /foo
|
|
|
|
* /foo/../../bar /bar
|
|
|
|
* /foo/./blah/.. /foo
|
|
|
|
* . .
|
|
|
|
* .. ..
|
|
|
|
* ./foo foo
|
|
|
|
* foo/../../../bar ../../bar
|
2004-12-13 20:05:09 +01:00
|
|
|
* CYGWIN:
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
* a:/foo/../.. a:/
|
|
|
|
* a:. a:
|
|
|
|
* a:.. a:..
|
|
|
|
* a:foo/../../blah a:../blah
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
/* preserve leading double-slash on pathnames (for UNC paths) */
|
|
|
|
if (path[0] && ISDIRSEP(path[0]) && path[1] && ISDIRSEP(path[1]))
|
|
|
|
very_start++;
|
|
|
|
#endif /* __CYGWIN__ */
|
|
|
|
|
|
|
|
for (cur = t = start = very_start; ; ) {
|
|
|
|
/* treat multiple '/'s as one '/' */
|
|
|
|
while (ISDIRSEP(*t))
|
|
|
|
t++;
|
|
|
|
|
|
|
|
if (*t == '\0') {
|
|
|
|
if (cur == path)
|
|
|
|
/* convert empty path to dot */
|
|
|
|
*cur++ = '.';
|
|
|
|
*cur = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t[0] == '.') {
|
|
|
|
if (!t[1] || ISDIRSEP(t[1])) {
|
|
|
|
t += 1;
|
|
|
|
continue;
|
|
|
|
} else if (t[1] == '.' && (!t[2] || ISDIRSEP(t[2]))) {
|
|
|
|
if (!isrooted && cur == start) {
|
|
|
|
if (cur != very_start)
|
|
|
|
*cur++ = DIRSEP;
|
|
|
|
*cur++ = '.';
|
|
|
|
*cur++ = '.';
|
|
|
|
start = cur;
|
|
|
|
} else if (cur != start)
|
|
|
|
while (--cur > start && !ISDIRSEP(*cur))
|
|
|
|
;
|
|
|
|
t += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur != very_start)
|
|
|
|
*cur++ = DIRSEP;
|
|
|
|
|
|
|
|
/* find/copy next component of pathname */
|
|
|
|
while (*t && !ISDIRSEP(*t))
|
|
|
|
*cur++ = *t++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
set_current_wd(char *path)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *p = path;
|
|
|
|
|
|
|
|
if (!p && !(p = ksh_get_wd((char *) 0, 0)))
|
|
|
|
p = null;
|
|
|
|
|
|
|
|
len = strlen(p) + 1;
|
|
|
|
|
|
|
|
if (len > current_wd_size)
|
|
|
|
current_wd = aresize(current_wd, current_wd_size = len, APERM);
|
|
|
|
memcpy(current_wd, p, len);
|
|
|
|
if (p != path && p != null)
|
|
|
|
afree(p, ATEMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef S_ISLNK
|
|
|
|
char *
|
2004-10-28 13:53:44 +02:00
|
|
|
get_phys_path(const char *path)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
XString xs;
|
|
|
|
char *xp;
|
|
|
|
|
|
|
|
Xinit(xs, xp, strlen(path) + 1, ATEMP);
|
|
|
|
|
|
|
|
xp = do_phys_path(&xs, xp, path);
|
|
|
|
|
|
|
|
if (!xp)
|
|
|
|
return (char *) 0;
|
|
|
|
|
|
|
|
if (Xlength(xs, xp) == 0)
|
|
|
|
Xput(xs, xp, DIRSEP);
|
|
|
|
Xput(xs, xp, '\0');
|
|
|
|
|
|
|
|
return Xclose(xs, xp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2004-10-28 13:53:44 +02:00
|
|
|
do_phys_path(XString *xsp, char *xp, const char *path)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
const char *p, *q;
|
2004-10-28 13:03:24 +02:00
|
|
|
size_t len;
|
|
|
|
int savepos, llen;
|
2004-09-21 16:03:58 +02:00
|
|
|
char lbuf[PATH_MAX];
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
Xcheck(*xsp, xp);
|
|
|
|
for (p = path; p; p = q) {
|
|
|
|
while (ISDIRSEP(*p))
|
|
|
|
p++;
|
|
|
|
if (!*p)
|
|
|
|
break;
|
2004-10-28 13:03:24 +02:00
|
|
|
len = (q = ksh_strchr_dirsep(p)) ? (size_t)(q - p) : strlen(p);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
if (len == 1 && p[0] == '.')
|
|
|
|
continue;
|
|
|
|
if (len == 2 && p[0] == '.' && p[1] == '.') {
|
|
|
|
while (xp > Xstring(*xsp, xp)) {
|
|
|
|
xp--;
|
|
|
|
if (ISDIRSEP(*xp))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
savepos = Xsavepos(*xsp, xp);
|
|
|
|
Xput(*xsp, xp, DIRSEP);
|
|
|
|
XcheckN(*xsp, xp, len + 1);
|
|
|
|
memcpy(xp, p, len);
|
|
|
|
xp += len;
|
|
|
|
*xp = '\0';
|
|
|
|
|
|
|
|
llen = readlink(Xstring(*xsp, xp), lbuf, sizeof(lbuf) - 1);
|
|
|
|
if (llen < 0) {
|
|
|
|
/* EINVAL means it wasn't a symlink... */
|
|
|
|
if (errno != EINVAL)
|
|
|
|
return (char *) 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lbuf[llen] = '\0';
|
|
|
|
|
|
|
|
/* If absolute path, start from scratch.. */
|
|
|
|
xp = ISABSPATH(lbuf) ? Xstring(*xsp, xp)
|
|
|
|
: Xrestpos(*xsp, xp, savepos);
|
|
|
|
if (!(xp = do_phys_path(xsp, xp, lbuf)))
|
|
|
|
return (char *) 0;
|
|
|
|
}
|
|
|
|
return xp;
|
|
|
|
}
|
|
|
|
#endif /* S_ISLNK */
|
|
|
|
|
|
|
|
#ifdef TEST
|
|
|
|
|
|
|
|
main(argc, argv)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
char *cp, cdpath[256], pwd[256], file[256], result[256];
|
|
|
|
|
|
|
|
printf("enter CDPATH: "); gets(cdpath);
|
|
|
|
printf("enter PWD: "); gets(pwd);
|
|
|
|
while (1) {
|
|
|
|
if (printf("Enter file: "), gets(file) == 0)
|
|
|
|
return 0;
|
|
|
|
cp = cdpath;
|
|
|
|
do {
|
|
|
|
rv = make_path(pwd, file, &cp, result, sizeof(result));
|
|
|
|
printf("make_path returns (%d), \"%s\" ", rv, result);
|
|
|
|
simplify_path(result);
|
|
|
|
printf("(simpifies to \"%s\")\n", result);
|
|
|
|
} while (cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* TEST */
|