git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v6 2/3] compat: add a basename() compatibility function
  2009-05-31  4:37 [PATCH v6 1/3] compat: add a mkstemps() " David Aguilar
@ 2009-05-31  4:37 ` David Aguilar
  2009-05-31  4:42   ` David Aguilar
  0 siblings, 1 reply; 4+ messages in thread
From: David Aguilar @ 2009-05-31  4:37 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, markus.heidelberg, jnareb, j.sixt, David Aguilar

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 2/3] compat: add a basename() compatibility function
  2009-05-31  4:37 ` [PATCH v6 2/3] compat: add a basename() " David Aguilar
@ 2009-05-31  4:42   ` David Aguilar
  2009-05-31  4:53     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: David Aguilar @ 2009-05-31  4:42 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, markus.heidelberg, jnareb, j.sixt

On Sat, May 30, 2009 at 09:37:54PM -0700, David Aguilar wrote:
> Some systems such as Windows lack libgen.h so provide a
> basename() implementation for cross-platform use.
> [...]
> 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


Thanks for bearing through this series everyone.. ;)

Can someone with better win32 knowledge let me know if the
USE_WIN32_FS stuff is needed for msysgit?

I would really like it if there was a way to do without the
#define.



> +	for (base = path; *path; path++) {
> +		if (is_dir_sep(*path)) {
> +			base = path + 1;
> +		}
> +	}
> +	return (char *)base;
> +}

-- 
		David

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 2/3] compat: add a basename() compatibility function
  2009-05-31  4:42   ` David Aguilar
@ 2009-05-31  4:53     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-05-31  4:53 UTC (permalink / raw)
  To: David Aguilar; +Cc: git, gitster, peff, markus.heidelberg, jnareb, j.sixt

David Aguilar <davvid@gmail.com> writes:

>> +#ifdef USE_WIN32_FS
>> +	/* Skip over the disk name in MSDOS pathnames. */
>> +	if (isalpha(path[0]) && path[1] == ':')
>> +		path += 2;
>> +#endif
>
> Thanks for bearing through this series everyone.. ;)
>
> Can someone with better win32 knowledge let me know if the
> USE_WIN32_FS stuff is needed for msysgit?
>
> I would really like it if there was a way to do without the
> #define.

Isn't this essentially the same as has_dos_drive_prefix()?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 2/3] compat: add a basename() compatibility function
@ 2009-05-31  8:11 j.sixt
  0 siblings, 0 replies; 4+ messages in thread
From: j.sixt @ 2009-05-31  8:11 UTC (permalink / raw)
  To: David Aguilar; +Cc: gitster, peff, markus.heidelberg, jnareb, git

On Sun 31/05/09 06:42 , David Aguilar davvid@gmail.com sent:
> On Sat, May 30, 2009 at 09:37:54PM -0700, David Aguilar wrote:
> > Some systems such as Windows lack libgen.h so provide a
> > basename() implementation for cross-platform use.
> > [...]
> > 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
> 
> Thanks for bearing through this series everyone.. ;)
> 
> Can someone with better win32 knowledge let me know if the
> USE_WIN32_FS stuff is needed for msysgit?

No, you don't need it: use

	if (has_dos_drive_prefix(path))
		path += 2;

without any #ifdef.

Thank _you_ for going through so many iterations.

Unfortunately, it may take me a day or two until I can test the patches on 
Windows again.

-- Hannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-31  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-31  8:11 [PATCH v6 2/3] compat: add a basename() compatibility function j.sixt
  -- strict thread matches above, loose matches on Subject: below --
2009-05-31  4:37 [PATCH v6 1/3] compat: add a mkstemps() " David Aguilar
2009-05-31  4:37 ` [PATCH v6 2/3] compat: add a basename() " David Aguilar
2009-05-31  4:42   ` David Aguilar
2009-05-31  4:53     ` Junio C Hamano

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).