git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: David Aguilar <davvid@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, markus.heidelberg@web.de,
	jnareb@gmail.com, j.sixt@viscovery.net,
	David Aguilar <davvid@gmail.com>
Subject: [PATCH v6 2/3] compat: add a basename() compatibility function
Date: Sat, 30 May 2009 21:37:54 -0700	[thread overview]
Message-ID: <1243744675-24160-2-git-send-email-davvid@gmail.com> (raw)
In-Reply-To: <1243744675-24160-1-git-send-email-davvid@gmail.com>

Some systems such as Windows lack libgen.h so provide a
basename() implementation for cross-platform use.

This introduces the NO_LIBGEN_H construct to the Makefile
and autoconf scripts.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 Makefile          |   12 ++++++++++++
 compat/basename.c |   19 +++++++++++++++++++
 config.mak.in     |    1 +
 configure.ac      |    6 ++++++
 git-compat-util.h |    7 +++++++
 5 files changed, 45 insertions(+), 0 deletions(-)
 create mode 100644 compat/basename.c

diff --git a/Makefile b/Makefile
index a70b5f0..caa3002 100644
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,8 @@ all::
 #
 # Define NO_MKSTEMPS if you don't have mkstemps in the C library.
 #
+# Define NO_LIBGEN_H if you don't have libgen.h.
+#
 # Define NO_SYS_SELECT_H if you don't have sys/select.h.
 #
 # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
@@ -834,6 +836,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
 	NO_PREAD = YesPlease
 	NO_OPENSSL = YesPlease
 	NO_CURL = YesPlease
+	NO_LIBGEN_H = UnfortunatelyYes
 	NO_SYMLINK_HEAD = YesPlease
 	NO_IPV6 = YesPlease
 	NO_SETENV = YesPlease
@@ -855,6 +858,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
 	NO_POSIX_ONLY_PROGRAMS = YesPlease
 	NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
 	NO_NSEC = YesPlease
+	USE_WIN32_FS = YesPlease
 	USE_WIN32_MMAP = YesPlease
 	UNRELIABLE_FSTAT = UnfortunatelyYes
 	OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
@@ -899,6 +903,11 @@ ifndef CC_LD_DYNPATH
 	endif
 endif
 
+ifdef NO_LIBGEN_H
+	COMPAT_CFLAGS += -DNO_LIBGEN_H
+	COMPAT_OBJS += compat/basename.o
+endif
+
 ifdef NO_CURL
 	BASIC_CFLAGS += -DNO_CURL
 else
@@ -1046,6 +1055,9 @@ else
 		COMPAT_OBJS += compat/win32mmap.o
 	endif
 endif
+ifdef USE_WIN32_FS
+	COMPAT_CFLAGS += -DWIN32_FS
+endif
 ifdef OBJECT_CREATION_USES_RENAMES
 	COMPAT_CFLAGS += -DOBJECT_CREATION_MODE=1
 endif
diff --git a/compat/basename.c b/compat/basename.c
new file mode 100644
index 0000000..c45716a
--- /dev/null
+++ b/compat/basename.c
@@ -0,0 +1,19 @@
+#include "../git-compat-util.h"
+
+/* Adapted from libiberty's basename.c.  */
+char *gitbasename (char *path)
+{
+	const char *base;
+
+#ifdef USE_WIN32_FS
+	/* Skip over the disk name in MSDOS pathnames. */
+	if (isalpha(path[0]) && path[1] == ':')
+		path += 2;
+#endif
+	for (base = path; *path; path++) {
+		if (is_dir_sep(*path)) {
+			base = path + 1;
+		}
+	}
+	return (char *)base;
+}
diff --git a/config.mak.in b/config.mak.in
index b6619af..e8d96e8 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -30,6 +30,7 @@ NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@
 NO_OPENSSL=@NO_OPENSSL@
 NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
+NO_LIBGEN_H=@NO_LIBGEN_H@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NO_SYS_SELECT_H=@NO_SYS_SELECT_H@
diff --git a/configure.ac b/configure.ac
index 953da07..3e7a0e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -627,6 +627,12 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS)
 ## (in default C library and libraries checked by AC_CHECK_LIB)
 AC_MSG_NOTICE([CHECKS for library functions])
 #
+# Define NO_LIBGEN_H if you don't have libgen.h.
+AC_CHECK_HEADER([libgen.h],
+[NO_LIBGEN_H=],
+[NO_LIBGEN_H=UnfortunatelyYes])
+AC_SUBST(NO_LIBGEN_H)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
diff --git a/git-compat-util.h b/git-compat-util.h
index 5a2d4e7..d248047 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -97,6 +97,13 @@
 #include "compat/mingw.h"
 #endif	/* __MINGW32__ */
 
+#ifndef NO_LIBGEN_H
+#include <libgen.h>
+#else
+#define basename gitbasename
+extern char *gitbasename(char *);
+#endif
+
 #ifndef NO_ICONV
 #include <iconv.h>
 #endif
-- 
1.6.3.1.178.g5b6b2

  reply	other threads:[~2009-05-31  4:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-31  4:37 [PATCH v6 1/3] compat: add a mkstemps() compatibility function David Aguilar
2009-05-31  4:37 ` David Aguilar [this message]
2009-05-31  4:37   ` [PATCH v6 3/3] diff: generate pretty filenames in prep_temp_blob() David Aguilar
2009-05-31  4:42   ` [PATCH v6 2/3] compat: add a basename() compatibility function David Aguilar
2009-05-31  4:53     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2009-05-31  8:11 j.sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1243744675-24160-2-git-send-email-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=jnareb@gmail.com \
    --cc=markus.heidelberg@web.de \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).