OSSP CVS Repository

ossp - Check-in [3788]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3788
Date: 2002-Jan-21 14:32:34 (local)
2002-Jan-21 13:32:34 (UTC)
User:rse
Branch:
Comment: Initial revision
Tickets:
Inspections:
Files:
ossp-pkg/path/ChangeLog      1.1 -> 1.1.1.1    
ossp-pkg/path/ChangeLog      added-> 1.1
ossp-pkg/path/README      1.1 -> 1.1.1.1    
ossp-pkg/path/README      added-> 1.1
ossp-pkg/path/TODO      1.1 -> 1.1.1.1    
ossp-pkg/path/TODO      added-> 1.1
ossp-pkg/path/aclocal.m4      1.1 -> 1.1.1.1    
ossp-pkg/path/aclocal.m4      added-> 1.1
ossp-pkg/path/path.h      1.1 -> 1.1.1.1    
ossp-pkg/path/path.h      added-> 1.1
ossp-pkg/path/path.pod      1.1 -> 1.1.1.1    
ossp-pkg/path/path.pod      added-> 1.1
ossp-pkg/path/path_abs2rel.c      1.1 -> 1.1.1.1    
ossp-pkg/path/path_abs2rel.c      added-> 1.1
ossp-pkg/path/path_rel2abs.c      1.1 -> 1.1.1.1    
ossp-pkg/path/path_rel2abs.c      added-> 1.1

ossp-pkg/path/ChangeLog -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,9 ----
+ 
+   o Taken FreeBSD 3.4's realpath.c/realpath.3 and created path_resolve.c
+     out of realpath.c, but support a size-restricted output buffer.
+   o Taken abs2rel.c/abs2rel.3 and rel2abs.c/rel2abs.3 from
+     PathConvert (http://www.tamacom.com/pathconvert/)
+   o Cleaned up the sources (K&R -> ANSI C, indentation, use path_ prefix, etc.)
+   o Added path.h
+   o Merged PathConverts's test suite into path_test.{c,pl}
+    


ossp-pkg/path/ChangeLog 1.1 -> 1.1.1.1



ossp-pkg/path/README -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,12 ----
+    ____       _   _     
+   |  _ \ __ _| |_| |__  
+   | |_) / _` | __| '_ \ 
+   |  __/ (_| | |_| | | |
+   |_|   \__,_|\__|_| |_|
+ 
+   Path - Filesystem Path Manipulation Library
+                       
+   This product includes software developed by the University of California,
+   Berkeley and its contributors. This product includes software developed by
+   Shigio Yamaguchi.
+ 


ossp-pkg/path/README 1.1 -> 1.1.1.1



ossp-pkg/path/TODO -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,14 ----
+ 
+ - add path_tmpfile() from BSD tmpfile(3) stuff
+ - add glob(*) from shpat
+ - add fnmatch(*) from shpat
+ - add tilde() from shpath/bres or bash-2.05a
+ 
+ - merge with shpat und proc/getcwd
+ 
+ - MAXPATHLEN should be PATH_MAXPATHLEN und
+   per AUtoconf herausgegfunden weredse
+ - path_test.pl in C umschreiben und in path_test.c einbauen
+ - path_test.c um path_resolve() checks erweitern
+ - path.pod per pod2man convertieren
+ 


ossp-pkg/path/TODO 1.1 -> 1.1.1.1



ossp-pkg/path/aclocal.m4 -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,117 ----
+ dnl ##
+ dnl ##  val - OSSP Value Library
+ dnl ##  Copyright (c) 2002 Ralf S. Engelschall <rse@engelschall.com>
+ dnl ##  Copyright (c) 2002 The OSSP Project <http://www.ossp.org/>
+ dnl ##  Copyright (c) 2002 Cable & Wireless Deutschland <http://www.cw.com/de/>
+ dnl ##
+ dnl ##  This file is part of OSSP val, a Value library which
+ dnl ##  can be found at http://www.ossp.org/pkg/val/.
+ dnl ##
+ dnl ##  Permission to use, copy, modify, and distribute this software for
+ dnl ##  any purpose with or without fee is hereby granted, provided that
+ dnl ##  the above copyright notice and this permission notice appear in all
+ dnl ##  copies.
+ dnl ##
+ dnl ##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ dnl ##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ dnl ##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ dnl ##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+ dnl ##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ dnl ##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ dnl ##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ dnl ##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ dnl ##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ dnl ##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ dnl ##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ dnl ##  SUCH DAMAGE.
+ dnl ##
+ dnl ##  aclocal.m4: GNU Autoconf local macro definitions
+ dnl ##
+ 
+ dnl ##
+ dnl ##  Check whether compiler option works
+ dnl ##
+ dnl ##  configure.in:
+ dnl ##    AC_COMPILER_OPTION(<name>, <display>, <option>,
+ dnl ##                       <action-success>, <action-failure>)
+ dnl ##
+ 
+ AC_DEFUN(AC_COMPILER_OPTION,[dnl
+ AC_MSG_CHECKING(whether compiler option(s) $2 work)
+ AC_CACHE_VAL(ac_cv_compiler_option_$1,[
+ SAVE_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $3"
+ AC_TRY_COMPILE([],[], ac_cv_compiler_option_$1=yes, ac_cv_compiler_option_$1=no)
+ CFLAGS="$SAVE_CFLAGS"
+ ])dnl
+ if test ".$ac_cv_compiler_option_$1" = .yes; then
+     ifelse([$4], , :, [$4])
+ else
+     ifelse([$5], , :, [$5])
+ fi
+ AC_MSG_RESULT([$ac_cv_compiler_option_$1])
+ ])dnl
+ 
+ dnl ##
+ dnl ##  Debugging Support
+ dnl ##
+ dnl ##  configure.in:
+ dnl ##    AC_CHECK_DEBUGGING
+ dnl ##
+ 
+ AC_DEFUN(AC_CHECK_DEBUGGING,[dnl
+ AC_ARG_ENABLE(debug,dnl
+ [  --enable-debug          build for debugging (default=no)],
+ [dnl
+ if test ".$ac_cv_prog_gcc" = ".yes"; then
+     case "$CFLAGS" in
+         *-O* ) ;;
+            * ) CFLAGS="$CFLAGS -O2" ;;
+     esac
+     case "$CFLAGS" in
+         *-g* ) ;;
+            * ) CFLAGS="$CFLAGS -g" ;;
+     esac
+     case "$CFLAGS" in
+         *-pipe* ) ;;
+               * ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
+     esac
+     AC_COMPILER_OPTION(defdbg, -DDEBUG, -DDEBUG, CFLAGS="$CFLAGS -DDEBUG")
+     AC_COMPILER_OPTION(ggdb3, -ggdb3, -ggdb3, CFLAGS="$CFLAGS -ggdb3")
+     CFLAGS="$CFLAGS -pedantic"
+     CFLAGS="$CFLAGS -Wall"
+     WMORE="-Wshadow -Wpointer-arith -Wcast-align -Winline"
+     WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Wnested-externs"
+     AC_COMPILER_OPTION(wmore, -W<xxx>, $WMORE, CFLAGS="$CFLAGS $WMORE")
+     AC_COMPILER_OPTION(wnolonglong, -Wno-long-long, -Wno-long-long, CFLAGS="$CFLAGS -Wno-long-long")
+ else
+     case "$CFLAGS" in
+         *-g* ) ;;
+            * ) CFLAGS="$CFLAGS -g" ;;
+     esac
+ fi
+ msg="enabled"
+ ],[
+ if test ".$ac_cv_prog_gcc" = ".yes"; then
+ case "$CFLAGS" in
+     *-pipe* ) ;;
+           * ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
+ esac
+ fi
+ case "$CFLAGS" in
+     *-g* ) CFLAGS=`echo "$CFLAGS" |\
+                    sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
+ esac
+ case "$CXXFLAGS" in
+     *-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
+                      sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
+ esac
+ msg=disabled
+ ])dnl
+ AC_MSG_CHECKING(for compilation debug mode)
+ AC_MSG_RESULT([$msg])
+ if test ".$msg" = .enabled; then
+     enable_shared=no
+ fi
+ ])
+ 


ossp-pkg/path/aclocal.m4 1.1 -> 1.1.1.1



ossp-pkg/path/path.h -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,10 ----
+ #ifndef _PATH_H_
+ #define _PATH_H_
+ 
+ char *path_abs2rel  (char *, size_t, const char *, const char *);
+ char *path_rel2abs  (char *, size_t, const char *, const char *);
+ char *path_resolve  (char *, size_t, const char *);
+ char *path_dirname  (char *, size_t, const char *);
+ char *path_basename (char *, size_t, const char *);
+ 
+ #endif /* _PATH_H_ */


ossp-pkg/path/path.h 1.1 -> 1.1.1.1



ossp-pkg/path/path.pod -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,176 ----
+ 
+ =pod
+ 
+ =head1 NAME
+ 
+ B<path> - Filesystem Path Manipulation Library
+ 
+ =head1 SYNOPSIS
+ 
+ #include "path.h"
+ 
+ char *B<path_abs2rel>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>, const char *I<base>);
+ 
+ char *B<path_rel2abs>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>, const char *I<base>);
+ 
+ char *B<path_resolve>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ char *B<path_dirname>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ char *B<path_basename>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ =head1 DESCRIPTION
+ 
+ B<Path> is a filesystem path conversion library. It allows one to
+ convert between absolute and relative paths and to resolve symlinks in a
+ path. The following Application Programming Interface (API) is provided
+ for this:
+ 
+ =over 4
+ 
+ =item char *B<path_abs2rel>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>, const char *I<base>);
+ 
+ This function make a relative path name from an absolute path name
+ I<path> based on a reference directory I<base>. The generated relative
+ path name is stored into the caller supplied buffer at I<outbuf>, but
+ never more than I<outsize> bytes are written. The resulting path name
+ may include symbolic links. The function doesn't check whether or not
+ any path exists. The function returns a pointer to I<outbuf> (the
+ relative path name) on success, and C<NULL> on error.
+ 
+ The function may fail with the following errors and set the external
+ variable C<errno> to indicate the particular error: C<EINVAL> (the
+ I<base> directory isn't an absolute path name or the I<outsize> argument
+ is zero) or C<ERANGE> (the I<outsize> argument is greater than zero but
+ smaller than the length of the pathname plus 1).
+ 
+ =item char *B<path_rel2abs>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>, const char *I<base>);
+ 
+ This function make an absolute path name from a relative path name
+ I<path> based on a reference directory I<base>. The generated absolute
+ path name is stored into the caller supplied buffer at I<outbuf>, but
+ never more than I<outsize> bytes are written. The resulting path name
+ may include symbolic links. The function doesn't check whether or not
+ any path exists. The function returns a pointer to I<outbuf> (the
+ absolute path name) on success, and C<NULL> on error.
+ 
+ The function may fail with the following errors and set the external
+ variable C<errno> to indicate the particular error: C<EINVAL> (the
+ I<base> directory isn't an absolute path name or the I<outsize> argument
+ is zero) or C<ERANGE> (the I<outsize> argument is greater than zero but
+ smaller than the length of the pathname plus 1).
+ 
+ =item char *B<path_resolve>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ This function resolves a path name I<path> into the corresponding
+ canonicalized absolute pathname. The generated absolute path name is
+ stored into the caller supplied buffer at I<outbuf>, but never more
+ than I<outsize> bytes are written. The function is capable to resolve
+ symbolic links, extra "C</>" characters and references to "C</./>" and
+ "C</../>". The function returns a pointer to I<outbuf> (the resolved
+ path name) on success, and C<NULL> on error.
+ 
+ The function may fail with an error and set the external variable
+ C<errno> for any of the errors specified for the library functions
+ chdir(2), close(2), fchdir(2), lstat(2), open(2), readlink(2) and
+ getcwd(3).
+ 
+ =item char *B<path_dirname>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ This function extracts the directory filename part from I<path> and stores it
+ into the caller supplied buffer at I<outbuf>, but never more than I<outsize>
+ bytes are written.  The function returns a pointer to I<outbuf> on success,
+ and C<NULL> on error.
+ 
+ =item char *B<path_basename>(char *I<outbuf>, const size_t I<outsize>, const char *I<path>);
+ 
+ This function extracts the base filename part from I<path> and stores it into
+ the caller supplied buffer at I<outbuf>, but never more than I<outsize> bytes
+ are written.  The function returns a pointer to I<outbuf> on success, and
+ C<NULL> on error.
+ 
+ =back
+ 
+ =head1 EXAMPLE
+ 
+  char result[MAXPATHLEN];
+  char *path = path_abs2rel(result, sizeof(result), "/usr/src/sys", "/usr/local/lib");
+ 
+ yields:
+ 
+  path == "../../src/sys"
+ 
+ Similarly,
+ 
+  path1 = path_abs2rel(result, sizeof(result), "/usr/src/sys", "/usr");
+  path2 = path_abs2rel(result, sizeof(result), "/usr/src/sys", "/usr/src/sys");
+ 
+ yields:
+ 
+  path1 == "src/sys"
+  path2 == "."
+ 
+ And
+ 
+  char *path = path_rel2abs(result, sizeof(result), "../../src/sys", "/usr/local/lib");
+ 
+ yields:
+ 
+  path == "/usr/src/sys"
+ 
+ Similarly,
+ 
+  path1 = rel2abs(result, sizeof(result), "src/sys", "/usr");
+  path2 = rel2abs(result, sizeof(result), ".", "/usr/src/sys");
+ 
+ yields:
+ 
+  path1 == "/usr/src/sys"
+  path2 == "/usr/src/sys"
+ 
+ =head1 BUGS
+ 
+ If the base directory includes symbolic links, the abs2rel(3) function
+ produces the wrong path. For example, if 'C</sys>' is a symbolic link to
+ 'C</usr/src/sys>',
+ 
+  char *path = path_abs2rel(result, sizeof(result), "/usr/local/lib", "/sys");
+ 
+ yields:
+ 
+  path == "../usr/local/lib" /* It's wrong!! */
+ 
+ You should convert the base directory into a real path in advance.
+ 
+  path = path_abs2rel(result, sizeof(result),
+                      "/sys/kern", 
+                      path_resolve(result2, sizeof(result2), "/sys"));
+ 
+ This then yields:
+ 
+  path == "../../../sys/kern"  /* It's correct but ... */
+ 
+ That is correct, but a little redundant. If you wish get the simple an-
+ swer 'C<kern>', do the following.
+ 
+  path = path_abs2rel(r0, sizeof(r0), 
+                      path_resolve(r1, sizeof(r1), "/sys/kern"), 
+                      path_resolve(r2, sizeof(r2), "/sys"));
+ 
+ The path_resolve(3) function assures correct result, but don't forget
+ that path_resolve(3) requires that all but the last component of the
+ path exist.
+ 
+ =head1 SEE ALSO
+ 
+ =head1 AUTHORS
+ 
+ The path_abs2rel() and path_rel2abs() function was originally written in
+ December 1997 by I<Shigio Yamaguchi> for his I<PathConvert> project. The
+ path_resolve() function is derived from FreeBSD's realpath(3) function
+ which was written in February 1994 by I<Jan-Simon Pendry>. The work off
+ of this code and the B<Path> library as a whole was written in January
+ 2000 by I<Ralf S. Engelschall>.
+ 
+ =cut
+ 


ossp-pkg/path/path.pod 1.1 -> 1.1.1.1



ossp-pkg/path/path_abs2rel.c -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,129 ----
+ 
+ /*
+  * Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
+  * Copyright (c) 1999 Tama Communications Corporation. All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *      This product includes software developed by Tama Communications
+  *      Corporation.
+  * 4. Neither the name of the author nor the names of any co-contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  */
+ 
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "path.h"
+ 
+ /*
+  * abs2rel: convert an absolute path name into relative.
+  */
+ char *
+ path_abs2rel(
+     char *result,
+     size_t size,
+     const char *path,
+     const char *base)
+ {
+     const char *pp, *bp, *branch;
+     const char *endp;
+     char *rp;
+ 
+     /* endp points the last position which is safe in the result buffer. */
+     endp = result + size - 1;
+ 
+     if (*path != '/') {
+         if (strlen(path) >= size)
+             goto erange;
+         strcpy(result, path);
+         goto finish;
+     } 
+     else if (*base != '/' || !size) {
+         errno = EINVAL;
+         return NULL;
+     } 
+     else if (size == 1) {
+         goto erange;
+     }
+ 
+     /*
+      * seek to branched point.
+      */
+     branch = path;
+     for (pp = path, bp = base; *pp && *bp && *pp == *bp; pp++, bp++)
+         if (*pp == '/')
+             branch = pp;
+     if ((*pp == 0 || (*pp == '/' && *(pp + 1) == 0)) &&
+         (*bp == 0 || (*bp == '/' && *(bp + 1) == 0))) {
+         rp = result;
+         *rp++ = '.';
+         if (*pp == '/' || *(pp - 1) == '/')
+             *rp++ = '/';
+         if (rp > endp)
+             goto erange;
+         *rp = 0;
+         goto finish;
+     }
+     if ((*pp == 0 && *bp == '/') || (*pp == '/' && *bp == 0))
+         branch = pp;
+ 
+     /*
+      * up to root.
+      */
+     rp = result;
+     for (bp = base + (branch - path); *bp; bp++) {
+         if (*bp == '/' && *(bp + 1) != 0) {
+             if (rp + 3 > endp)
+                 goto erange;
+             *rp++ = '.';
+             *rp++ = '.';
+             *rp++ = '/';
+         }
+     }
+     if (rp > endp)
+         goto erange;
+     *rp = 0;
+ 
+     /*
+      * down to leaf.
+      */
+     if (*branch) {
+         if (rp + strlen(branch + 1) > endp)
+             goto erange;
+         strcpy(rp, branch + 1);
+     } 
+     else {
+         *--rp = 0;
+     }
+ 
+ finish:
+     return result;
+ 
+ erange:
+     errno = ERANGE;
+     return NULL;
+ }
+ 


ossp-pkg/path/path_abs2rel.c 1.1 -> 1.1.1.1



ossp-pkg/path/path_rel2abs.c -> 1.1

*** /dev/null    Sat Nov 23 01:12:03 2024
--- -    Sat Nov 23 01:12:03 2024
***************
*** 0 ****
--- 1,141 ----
+ 
+ /*
+  * Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
+  * Copyright (c) 1999 Tama Communications Corporation. All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions
+  * are met:
+  * 1. Redistributions of source code must retain the above copyright
+  *    notice, this list of conditions and the following disclaimer.
+  * 2. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *      This product includes software developed by Tama Communications
+  *      Corporation.
+  * 4. Neither the name of the author nor the names of any co-contributors
+  *    may be used to endorse or promote products derived from this software
+  *    without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  * SUCH DAMAGE.
+  */
+ 
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "path.h"
+ 
+ /*
+  * rel2abs: convert an relative path name into absolute.
+  */
+ char *
+ path_rel2abs(
+     char *result,
+     size_t size,
+     const char *path,
+     const char *base)
+ {
+     const char *pp, *bp;
+     const char *endp;
+     char *rp;
+     int length;
+ 
+     /* endp points the last position which is safe in the result buffer. */
+     endp = result + size - 1;
+ 
+     if (*path == '/') {
+         if (strlen(path) >= size)
+             goto erange;
+         strcpy(result, path);
+         goto finish;
+     } 
+     else if (*base != '/' || !size) {
+         errno = EINVAL;
+         return (NULL);
+     } 
+     else if (size == 1) {
+         goto erange;
+     }
+ 
+     if (!strcmp(path, ".") || !strcmp(path, "./")) {
+         if (strlen(base) >= size)
+             goto erange;
+         strcpy(result, base);
+ 
+         /* rp points the last char. */
+         rp = result + strlen(base) - 1;
+         if (*rp == '/')
+             *rp = 0;
+         else
+             rp++;
+ 
+         /* rp point NULL char */
+         if (*++path == '/') {
+             /* Append '/' to the tail of path name. */
+             *rp++ = '/';
+             if (rp > endp)
+                 goto erange;
+             *rp = 0;
+         }
+         goto finish;
+     }
+     bp = base + strlen(base);
+     if (*(bp - 1) == '/')
+         --bp;
+ 
+     /*
+      * up to root.
+      */
+     for (pp = path; *pp && *pp == '.'; ) {
+         if (!strncmp(pp, "../", 3)) {
+             pp += 3;
+             while (bp > base && *--bp != '/')
+                 ;
+         } 
+         else if (!strncmp(pp, "./", 2)) {
+             pp += 2;
+         } 
+         else if (!strncmp(pp, "..\0", 3)) {
+             pp += 2;
+             while (bp > base && *--bp != '/')
+                 ;
+         } 
+         else
+             break;
+     }
+ 
+     /*
+      * down to leaf.
+      */
+     length = bp - base;
+     if (length >= size)
+         goto erange;
+     strncpy(result, base, length);
+     rp = result + length;
+     if (*pp || *(pp - 1) == '/' || length == 0)
+         *rp++ = '/';
+     if (rp + strlen(pp) > endp)
+         goto erange;
+     strcpy(rp, pp);
+ 
+ finish:
+     return result;
+ 
+ erange:
+     errno = ERANGE;
+     return (NULL);
+ }
+ 


ossp-pkg/path/path_rel2abs.c 1.1 -> 1.1.1.1


CVSTrac 2.0.1