[Libsysio-commit] HEAD: libsysio/src chdir.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2008-04-14 23:22:51
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32572 Modified Files: chdir.c Log Message: The routine _sysio_p_path has moved to inode.c for general use by others. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -b -B -p -r1.31 -r1.32 --- chdir.c 21 Sep 2007 19:41:37 -0000 1.31 +++ chdir.c 14 Apr 2008 23:22:47 -0000 1.32 @@ -143,100 +143,6 @@ sysio_sym_weak_alias(SYSIO_INTERFACE_NAM PREPEND(__, SYSIO_INTERFACE_NAME(chdir))) #endif -/* - * Return path tracked by the path ancestor chain. - * - * If the buf pointer is NULL, a buffer large enough to hold the path - * is allocated from the heap. - */ - -static int -_sysio_p_path(struct pnode *pno, char **buf, size_t size) -{ - struct pnode *cur; - size_t len; - size_t n; - char *cp; - - cur = pno; - - if (!size && buf && *buf) - return -EINVAL; - - /* - * Walk up the tree to the root, summing the component name - * lengths and counting the vertices. - */ - len = 0; - n = 0; - do { - /* - * If this is a covering path-node then the name should be - * the *covered* nodes name, not this one unless we are at - * the root of the name-space. - */ - while (pno == pno->p_mount->mnt_root && - pno != pno->p_parent) - pno = pno->p_mount->mnt_covers; - - /* - * Add length of this component to running sum and - * account for this vertex. - */ - assert((len >= pno->p_base->pb_key.pbk_name.len && - (size_t )~0 - pno->p_base->pb_key.pbk_name.len > len) || - (size_t )~0 - len > pno->p_base->pb_key.pbk_name.len); - len += pno->p_base->pb_key.pbk_name.len; - n++; - assert(n); - pno = pno->p_parent; - } while (pno && pno != pno->p_parent); - if (!pno) - return -ENOENT; - - if (!*buf) - size = len + n + 1; - if (len >= size || n >= size - len) - return -ERANGE; - if (!*buf) { - /* - * Allocate path buffer from the heap. - */ - *buf = malloc(size * sizeof(char)); - if (!*buf) - return -ENOMEM; - } - - /* - * Fill in the path buffer. - */ - pno = cur; - cp = *buf + len + n; - *cp = '\0'; /* NUL terminate */ - do { - /* - * If this is a covering path-node then the name should be - * the *covered* nodes name, not this one unless we are at - * the root of the name-space. - */ - while (pno == pno->p_mount->mnt_root && - pno != pno->p_parent ) - pno = pno->p_mount->mnt_covers; - - /* - * Add component and separator. - */ - cp -= pno->p_base->pb_key.pbk_name.len; - (void )memcpy(cp, pno->p_base->pb_key.pbk_name.name, - pno->p_base->pb_key.pbk_name.len); - - *--cp = PATH_SEPARATOR; - pno = pno->p_parent; - } while (pno != pno->p_parent); - - return 0; -} - char * SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size) { |