- (djm) Rest of Bug #499: Import a basename() function from OpenBSD libc

This commit is contained in:
Damien Miller 2003-02-24 12:55:55 +11:00
parent b16f874d89
commit 8d8168a255
6 changed files with 93 additions and 6 deletions

View File

@ -82,6 +82,7 @@
- (djm) Bug #501: gai_strerror should return char*;
fix from dtucker@zip.com.au
- (djm) Most of Bug #499: Cygwin compile fixes for new progressmeter
- (djm) Rest of Bug #499: Import a basename() function from OpenBSD libc
20030211
- (djm) Cygwin needs libcrypt too. Patch from vinschen@redhat.com
@ -1182,4 +1183,4 @@
save auth method before monitor_reset_key_state(); bugzilla bug #284;
ok provos@
$Id: ChangeLog,v 1.2618 2003/02/24 01:47:15 djm Exp $
$Id: ChangeLog,v 1.2619 2003/02/24 01:55:55 djm Exp $

View File

@ -1,4 +1,4 @@
# $Id: configure.ac,v 1.107 2003/02/24 01:47:16 djm Exp $
# $Id: configure.ac,v 1.108 2003/02/24 01:55:55 djm Exp $
AC_INIT
AC_CONFIG_SRCDIR([ssh.c])
@ -601,7 +601,7 @@ AC_ARG_WITH(tcp-wrappers,
)
dnl Checks for library functions.
AC_CHECK_FUNCS(arc4random b64_ntop bcopy bindresvport_sa \
AC_CHECK_FUNCS(arc4random b64_ntop bcopy basename bindresvport_sa \
clock fchmod fchown freeaddrinfo futimes gai_strerror \
getaddrinfo getcwd getgrouplist getnameinfo getopt getpeereid\
getrlimit getrusage getttyent glob inet_aton inet_ntoa \

View File

@ -1,4 +1,4 @@
# $Id: Makefile.in,v 1.24 2003/01/07 06:04:18 djm Exp $
# $Id: Makefile.in,v 1.25 2003/02/24 01:55:56 djm Exp $
sysconfdir=@sysconfdir@
piddir=@piddir@
@ -16,7 +16,7 @@ RANLIB=@RANLIB@
INSTALL=@INSTALL@
LDFLAGS=-L. @LDFLAGS@
OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o

73
openbsd-compat/basename.c Normal file
View File

@ -0,0 +1,73 @@
/* $OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``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 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 "includes.h"
#if !defined(HAVE_BASENAME)
#ifndef lint
static char rcsid[] = "$OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $";
#endif /* not lint */
char *
basename(const char *path)
{
static char bname[MAXPATHLEN];
register const char *endp, *startp;
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
(void)strlcpy(bname, ".", sizeof bname);
return(bname);
}
/* Strip trailing slashes */
endp = path + strlen(path) - 1;
while (endp > path && *endp == '/')
endp--;
/* All slashes become "/" */
if (endp == path && *endp == '/') {
(void)strlcpy(bname, "/", sizeof bname);
return(bname);
}
/* Find the start of the base */
startp = endp;
while (startp > path && *(startp - 1) != '/')
startp--;
if (endp - startp + 2 > sizeof(bname)) {
errno = ENAMETOOLONG;
return(NULL);
}
strlcpy(bname, startp, endp - startp + 2);
return(bname);
}
#endif /* !defined(HAVE_BASENAME) */

12
openbsd-compat/basename.h Normal file
View File

@ -0,0 +1,12 @@
/* $Id: basename.h,v 1.1 2003/02/24 01:55:56 djm Exp $ */
#ifndef _BASENAME_H
#define _BASENAME_H
#include "config.h"
#if !defined(HAVE_BASENAME)
char *getcwd(char *pt, size_t size);
#endif /* !defined(HAVE_BASENAME) */
#endif /* _BASENAME_H */

View File

@ -1,4 +1,4 @@
/* $Id: openbsd-compat.h,v 1.18 2003/01/07 06:04:18 djm Exp $ */
/* $Id: openbsd-compat.h,v 1.19 2003/02/24 01:55:56 djm Exp $ */
#ifndef _OPENBSD_H
#define _OPENBSD_H
@ -6,6 +6,7 @@
#include "config.h"
/* OpenBSD function replacements */
#include "basename.h"
#include "bindresvport.h"
#include "getcwd.h"
#include "realpath.h"