summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2003-02-24 12:55:55 +1100
committerDamien Miller <djm@mindrot.org>2003-02-24 12:55:55 +1100
commit8d8168a255c17ca343865d1ee4962f2cba46b2d8 (patch)
treecbe3a80fcef437e14d3564dbcefff867556467c3
parentb16f874d89402333aabcc7988de59766934bf83d (diff)
- (djm) Rest of Bug #499: Import a basename() function from OpenBSD libc
-rw-r--r--ChangeLog3
-rw-r--r--configure.ac4
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/basename.c73
-rw-r--r--openbsd-compat/basename.h12
-rw-r--r--openbsd-compat/openbsd-compat.h3
6 files changed, 93 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 6650c997..008a7f4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 $
diff --git a/configure.ac b/configure.ac
index 6965c05f..20110761 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 \
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 8b1e5b53..8615e363 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -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
diff --git a/openbsd-compat/basename.c b/openbsd-compat/basename.c
new file mode 100644
index 00000000..5a3823bc
--- /dev/null
+++ b/openbsd-compat/basename.c
@@ -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) */
diff --git a/openbsd-compat/basename.h b/openbsd-compat/basename.h
new file mode 100644
index 00000000..0a14ff5c
--- /dev/null
+++ b/openbsd-compat/basename.h
@@ -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 */
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index dcb7ba15..c3e19b9c 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -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"