* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)path.c 5.1 (Berkeley) %G%";
* These functions manipulate paths in PATH_T structures.
* They eliminate multiple slashes in paths when they notice them,
* and keep the path non-slash terminated.
* Both path_set() and path_append() return 0 if the requested name
#define STRIP_TRAILING_SLASH(p) { \
while ((p)->p_end > (p)->p_path && (p)->p_end[-1] == '/') \
* Move specified string into path. Convert "" to "." to handle BSD
* semantics for a null path. Strip trailing slashes.
if (strlen(string
) > MAXPATHLEN
) {
"%s: %s: name too long.\n", progname
, string
);
(void)strcpy(p
->p_path
, string
);
p
->p_end
= p
->p_path
+ strlen(p
->p_path
);
if (p
->p_path
== p
->p_end
) {
* Append specified string to path, inserting '/' if necessary. Return a
* pointer to the old end of path for restoration.
path_append(p
, name
, len
)
/* The "+ 1" accounts for the '/' between old path and name. */
if ((len
+ p
->p_end
- p
->p_path
+ 1) > MAXPATHLEN
) {
"%s: %s/%s: name too long.\n", progname
, p
->p_path
, name
);
* This code should always be executed, since paths shouldn't
if (p
->p_end
[-1] != '/') {
(void)strncat(p
->p_end
, name
, len
);
* Restore path to previous value. (As returned by path_append.)
* Return basename of path.
basename
= rindex(p
->p_path
, '/');
return(basename
? basename
+ 1 : p
->p_path
);