FreeBSD Bugzilla – Attachment 5416 Details for
Bug 12962
basename(3) and dirname(3) part 2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
file.shar
file.shar (text/plain), 11.92 KB, created by
howardjp
on 1999-08-04 14:10:01 UTC
(
hide
)
Description:
file.shar
Filename:
MIME Type:
Creator:
howardjp
Created:
1999-08-04 14:10:01 UTC
Size:
11.92 KB
patch
obsolete
># This is a shell archive. Save it in a file, remove anything before ># this line, and then unpack it by entering "sh file". Note, it may ># create directories; files and directories will be owned by you and ># have default permissions. ># ># This archive contains: ># ># basename.3 ># basename.c ># dirname.3 ># dirname.c ># >echo x - basename.3 >sed 's/^X//' >basename.3 << 'END-of-basename.3' >X.\" >X.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> >X.\" All rights reserved. >X.\" >X.\" Redistribution and use in source and binary forms, with or without >X.\" modification, are permitted provided that the following conditions >X.\" are met: >X.\" 1. Redistributions of source code must retain the above copyright >X.\" notice, this list of conditions and the following disclaimer. >X.\" 2. Redistributions in binary form must reproduce the above copyright >X.\" notice, this list of conditions and the following disclaimer in the >X.\" documentation and/or other materials provided with the distribution. >X.\" 3. The name of the author may not be used to endorse or promote products >X.\" derived from this software without specific prior written permission. >X.\" >X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, >X.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY >X.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL >X.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >X.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >X.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; >X.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, >X.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR >X.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >X.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >X.\" >X.\" $OpenBSD: basename.3,v 1.11 1999/06/04 01:30:10 aaron Exp $ >X.\" >X.Dd August 17, 1997 >X.Dt BASENAME 3 >X.Os >X.Sh NAME >X.Nm basename >X.Nd extract the base portion of a pathname >X.Sh SYNOPSIS >X.Fd #include <libgen.h> >X.Ft char * >X.Fn basename "const char *path" >X.Sh DESCRIPTION >XThe >X.Fn basename >Xfunction >Xreturns the last component from the pathname pointed to by >X.Ar path , >Xdeleting any trailing >X.Sq \&/ >Xcharacters. If >X.Ar path >Xconsists entirely of >X.Sq \&/ >Xcharacters, a pointer to the string >X.Qq \&/ >Xis returned. If >X.Ar path >Xis a null pointer or the empty string, a pointer to the string >X.Qq \&. >Xis returned. >X.Sh RETURN VALUES >XOn successful completion, >X.Fn basename >Xreturns a pointer to the last component of >X.Ar path . >X.Pp >XIf >X.Fn basename >Xfails, a null pointer is returned and the global variable >X.Va errno >Xis set to indicate the error. >X.Sh ERRORS >XThe following error codes may be set in >X.Va errno : >X.Bl -tag -width Er >X.It Bq Er ENAMETOOLONG >XThe path component to be returned was larger than >X.Dv MAXPATHLEN . >X.El >X.Sh WARNINGS >X.Fn basename >Xreturns a pointer to internal static storage space that will be overwritten >Xby subsequent calls. >X.Sh SEE ALSO >X.Xr basename 1 , >X.Xr dirname 1 , >X.Xr dirname 3 >X.Sh STANDARDS >XThe >X.Fn basename >Xfunction conforms to >X.St -xpg4.2 . >X.Sh HISTORY >XThe >X.Fn basename >Xfunction first appeared in >X.Ox 2.2 . >X.Sh AUTHOR >XTodd C. Miller <Todd.Miller@courtesan.com> >END-of-basename.3 >echo x - basename.c >sed 's/^X//' >basename.c << 'END-of-basename.c' >X/* $OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ >X >X/* >X * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> >X * All rights reserved. >X * >X * Redistribution and use in source and binary forms, with or without >X * modification, are permitted provided that the following conditions >X * are met: >X * 1. Redistributions of source code must retain the above copyright >X * notice, this list of conditions and the following disclaimer. >X * 2. Redistributions in binary form must reproduce the above copyright >X * notice, this list of conditions and the following disclaimer in the >X * documentation and/or other materials provided with the distribution. >X * 3. The name of the author may not be used to endorse or promote products >X * derived from this software without specific prior written permission. >X * >X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, >X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY >X * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL >X * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >X * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >X * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; >X * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, >X * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR >X * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >X */ >X >X#ifndef lint >Xstatic char rcsid[] = "$OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; >X#endif /* not lint */ >X >X#include <errno.h> >X#include <libgen.h> >X#include <string.h> >X#include <sys/param.h> >X >Xchar * >Xbasename(path) >X const char *path; >X{ >X static char bname[MAXPATHLEN]; >X register const char *endp, *startp; >X >X /* Empty or NULL string gets treated as "." */ >X if (path == NULL || *path == '\0') { >X (void)strcpy(bname, "."); >X return(bname); >X } >X >X /* Strip trailing slashes */ >X endp = path + strlen(path) - 1; >X while (endp > path && *endp == '/') >X endp--; >X >X /* All slashes becomes "/" */ >X if (endp == path && *endp == '/') { >X (void)strcpy(bname, "/"); >X return(bname); >X } >X >X /* Find the start of the base */ >X startp = endp; >X while (startp > path && *(startp - 1) != '/') >X startp--; >X >X if (endp - startp + 1 > sizeof(bname)) { >X errno = ENAMETOOLONG; >X return(NULL); >X } >X (void)strncpy(bname, startp, endp - startp + 1); >X bname[endp - startp + 1] = '\0'; >X return(bname); >X} >END-of-basename.c >echo x - dirname.3 >sed 's/^X//' >dirname.3 << 'END-of-dirname.3' >X.\" >X.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> >X.\" All rights reserved. >X.\" >X.\" Redistribution and use in source and binary forms, with or without >X.\" modification, are permitted provided that the following conditions >X.\" are met: >X.\" 1. Redistributions of source code must retain the above copyright >X.\" notice, this list of conditions and the following disclaimer. >X.\" 2. Redistributions in binary form must reproduce the above copyright >X.\" notice, this list of conditions and the following disclaimer in the >X.\" documentation and/or other materials provided with the distribution. >X.\" 3. The name of the author may not be used to endorse or promote products >X.\" derived from this software without specific prior written permission. >X.\" >X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, >X.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY >X.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL >X.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >X.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >X.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; >X.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, >X.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR >X.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >X.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >X.\" >X.\" $OpenBSD: dirname.3,v 1.8 1999/07/17 09:32:30 downsj Exp $ >X.\" >X.Dd August 17, 1997 >X.Dt DIRNAME 3 >X.Os >X.Sh NAME >X.Nm dirname >X.Nd extract the directory portition of a pathname >X.Sh SYNOPSIS >X.Fd #include <libgen.h> >X.Ft char * >X.Fn dirname "const char *path" >X.Sh DESCRIPTION >XThe >X.Fn dirname >Xfunction >Xis the converse of >X.Xr basename 3 ; >Xit returns a pointer to the parent directory of the pathname pointed to by >X.Ar path . >XAny trailing >X.Sq \&/ >Xcharacters are not counted as part of the directory >Xname. If >X.Ar path >Xis a null pointer, the empty string, or contains no >X.Sq \&/ >Xcharacters, >X.Fn dirname >Xreturns a pointer to the string >X.Qq \&. , >Xsignifying the current directory. >X.Sh RETURN VALUES >XOn successful completion, >X.Fn dirname >Xreturns a pointer to the parent directory of >X.Ar path . >X.Pp >XIf >X.Fn dirname >Xfails, a null pointer is returned and the global variable >X.Va errno >Xis set to indicate the error. >X.Sh ERRORS >XThe following error codes may be set in >X.Va errno : >X.Bl -tag -width Er >X.It Bq Er ENAMETOOLONG >XThe path component to be returned was larger than >X.Dv MAXPATHLEN . >X.El >X.Sh WARNINGS >X.Fn dirname >Xreturns a pointer to internal static storage space that will be overwritten >Xby subsequent calls (each function has its own separate storage). >X.Pp >XOther vendor implementations of >X.Fn dirname >Xmay modify the contents of the string passed to >X.Fn dirname ; >Xthis should be taken into account when writing code which calls this function >Xif portability is desired. >X.Sh SEE ALSO >X.Xr basename 1 , >X.Xr dirname 1 , >X.Xr basename 3 >X.Sh STANDARDS >XThe >X.Fn dirname >Xfunction conforms to >X.St -xpg4.2 . >X.Sh HISTORY >XThe >X.Fn dirname >Xfunction first appeared in >X.Ox 2.2 . >X.Sh AUTHOR >XTodd C. Miller <Todd.Miller@courtesan.com> >END-of-dirname.3 >echo x - dirname.c >sed 's/^X//' >dirname.c << 'END-of-dirname.c' >X/* $OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $ */ >X >X/* >X * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> >X * All rights reserved. >X * >X * Redistribution and use in source and binary forms, with or without >X * modification, are permitted provided that the following conditions >X * are met: >X * 1. Redistributions of source code must retain the above copyright >X * notice, this list of conditions and the following disclaimer. >X * 2. Redistributions in binary form must reproduce the above copyright >X * notice, this list of conditions and the following disclaimer in the >X * documentation and/or other materials provided with the distribution. >X * 3. The name of the author may not be used to endorse or promote products >X * derived from this software without specific prior written permission. >X * >X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, >X * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY >X * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL >X * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >X * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >X * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; >X * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, >X * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR >X * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF >X * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >X */ >X >X#ifndef lint >Xstatic char rcsid[] = "$OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; >X#endif /* not lint */ >X >X#include <errno.h> >X#include <libgen.h> >X#include <string.h> >X#include <sys/param.h> >X >Xchar * >Xdirname(path) >X const char *path; >X{ >X static char bname[MAXPATHLEN]; >X register const char *endp; >X >X /* Empty or NULL string gets treated as "." */ >X if (path == NULL || *path == '\0') { >X (void)strcpy(bname, "."); >X return(bname); >X } >X >X /* Strip trailing slashes */ >X endp = path + strlen(path) - 1; >X while (endp > path && *endp == '/') >X endp--; >X >X /* Find the start of the dir */ >X while (endp > path && *endp != '/') >X endp--; >X >X /* Either the dir is "/" or there are no slashes */ >X if (endp == path) { >X (void)strcpy(bname, *endp == '/' ? "/" : "."); >X return(bname); >X } else { >X do { >X endp--; >X } while (endp > path && *endp == '/'); >X } >X >X if (endp - path + 1 > sizeof(bname)) { >X errno = ENAMETOOLONG; >X return(NULL); >X } >X (void)strncpy(bname, path, endp - path + 1); >X bname[endp - path + 1] = '\0'; >X return(bname); >X} >END-of-dirname.c >exit
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 12962
: 5416