summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2005-11-10 16:42:51 +1100
committerDarren Tucker <dtucker@zip.com.au>2005-11-10 16:42:51 +1100
commitad1dada0b4c2d450346984c88e3bc74cdfe2a888 (patch)
treec9b01256ba5f8e01f551526db62f1a807404a3b4
parent09471d8a1f7e46116ba44f0f08c756196dbf6c70 (diff)
- (dtucker) [openbsd-compat/basename.c] Update from OpenBSD 1.11 -> 1.14.
Removal of rcsid, will no longer strlcpy parts of the string.
-rw-r--r--ChangeLog4
-rw-r--r--openbsd-compat/basename.c35
2 files changed, 21 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 5a1be997f..a484b95ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,8 @@
21 - (dtucker) [openbsd-compat/sigact.h] Add "OPENBSD ORIGINAL" marker. 21 - (dtucker) [openbsd-compat/sigact.h] Add "OPENBSD ORIGINAL" marker.
22 - (dtucker) [openbsd-compat/strmode.c] Update from OpenBSD 1.5 -> 1.7. 22 - (dtucker) [openbsd-compat/strmode.c] Update from OpenBSD 1.5 -> 1.7.
23 Removal of rcsid, "whiteout" inode type. 23 Removal of rcsid, "whiteout" inode type.
24 - (dtucker) [openbsd-compat/basename.c] Update from OpenBSD 1.11 -> 1.14.
25 Removal of rcsid, will no longer strlcpy parts of the string.
24 26
2520051105 2720051105
26 - (djm) OpenBSD CVS Sync 28 - (djm) OpenBSD CVS Sync
@@ -3263,4 +3265,4 @@
3263 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 3265 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
3264 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 3266 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
3265 3267
3266$Id: ChangeLog,v 1.3965 2005/11/10 05:38:54 dtucker Exp $ 3268$Id: ChangeLog,v 1.3966 2005/11/10 05:42:51 dtucker Exp $
diff --git a/openbsd-compat/basename.c b/openbsd-compat/basename.c
index 5171cd64c..ad040e139 100644
--- a/openbsd-compat/basename.c
+++ b/openbsd-compat/basename.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $ */ 1/* $OpenBSD: basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -21,31 +21,30 @@
21#include "includes.h" 21#include "includes.h"
22#ifndef HAVE_BASENAME 22#ifndef HAVE_BASENAME
23 23
24#ifndef lint
25static char rcsid[] = "$OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $";
26#endif /* not lint */
27
28char * 24char *
29basename(const char *path) 25basename(const char *path)
30{ 26{
31 static char bname[MAXPATHLEN]; 27 static char bname[MAXPATHLEN];
32 register const char *endp, *startp; 28 size_t len;
29 const char *endp, *startp;
33 30
34 /* Empty or NULL string gets treated as "." */ 31 /* Empty or NULL string gets treated as "." */
35 if (path == NULL || *path == '\0') { 32 if (path == NULL || *path == '\0') {
36 (void)strlcpy(bname, ".", sizeof bname); 33 bname[0] = '.';
37 return(bname); 34 bname[1] = '\0';
35 return (bname);
38 } 36 }
39 37
40 /* Strip trailing slashes */ 38 /* Strip any trailing slashes */
41 endp = path + strlen(path) - 1; 39 endp = path + strlen(path) - 1;
42 while (endp > path && *endp == '/') 40 while (endp > path && *endp == '/')
43 endp--; 41 endp--;
44 42
45 /* All slashes become "/" */ 43 /* All slashes becomes "/" */
46 if (endp == path && *endp == '/') { 44 if (endp == path && *endp == '/') {
47 (void)strlcpy(bname, "/", sizeof bname); 45 bname[0] = '/';
48 return(bname); 46 bname[1] = '\0';
47 return (bname);
49 } 48 }
50 49
51 /* Find the start of the base */ 50 /* Find the start of the base */
@@ -53,12 +52,14 @@ basename(const char *path)
53 while (startp > path && *(startp - 1) != '/') 52 while (startp > path && *(startp - 1) != '/')
54 startp--; 53 startp--;
55 54
56 if (endp - startp + 2 > sizeof(bname)) { 55 len = endp - startp + 1;
56 if (len >= sizeof(bname)) {
57 errno = ENAMETOOLONG; 57 errno = ENAMETOOLONG;
58 return(NULL); 58 return (NULL);
59 } 59 }
60 strlcpy(bname, startp, endp - startp + 2); 60 memcpy(bname, startp, len);
61 return(bname); 61 bname[len] = '\0';
62 return (bname);
62} 63}
63 64
64#endif /* !defined(HAVE_BASENAME) */ 65#endif /* !defined(HAVE_BASENAME) */