head 1.4; access; symbols INITIAL:1.1.1.1 VENDOR:1.1.1; locks; strict; comment @ * @; 1.4 date 2003.02.16.11.39.22; author rse; state Exp; branches; next 1.3; 1.3 date 2003.02.16.11.38.11; author rse; state Exp; branches; next 1.2; 1.2 date 2002.08.03.10.23.41; author rse; state Exp; branches; next 1.1; 1.1 date 2002.01.21.13.32.35; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2002.01.21.13.32.35; author rse; state Exp; branches; next ; desc @@ 1.4 log @update copyright messages for new year 2003 @ text @/* ** OSSP path - Filesystem Path Manipulation ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Cable & Wireless Deutschland ** ** This file is part of OSSP path, a filesystem path manipulation library ** which can be found at http://www.ossp.org/pkg/lib/path/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** 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. ** ** path_basename.c: base filename extraction */ /*- * Copyright (c) 2000 Chris Costello * 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. * * 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 #include #include "path.h" char * path_basename( char *outbuf, size_t outsize, const char *path) { const char *cp; size_t len; int n; /* argument consistency check */ if (path == NULL || *path == '\0') return (strncpy(outbuf, ".", outsize)); /* skip leading slashes */ len = strspn(path, "/"); if (len > 0) path += len - 1; if (path[0] == '/' && path[1] == '\0') return (strncpy(outbuf, "/", outsize)); /* skip trailing slashes. */ len = strlen(path) - 1; for (; len > 0 && path[len] == '/'; len--) ; cp = path + len; /* look for the beginning of the final path component */ for (; *cp != '/' && cp > path; cp--) ; /* copy basename to result buffer */ if (cp != path) cp++; /* the path consisted of more than one component */ n = len - (cp - path) + 1; if (n > MAXPATHLEN) n = MAXPATHLEN; strncpy(outbuf, cp, n); outbuf[n] = '\0'; return outbuf; } @ 1.3 log @remove trailing whitespaces from source files @ text @d3 3 a5 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 The OSSP Project ** Copyright (c) 2002 Cable & Wireless Deutschland @ 1.2 log @source tree cleanups @ text @d77 1 a77 1 /* skip leading slashes */ @ 1.1 log @Initial revision @ text @d1 29 @ 1.1.1.1 log @Welcome OSSP path (filesystem path manipulation library) This is currently just a collection of reused components, assembled together from various vendor sources. @ text @@