Skip to content

Ensure that we can build without libgen.h

Johannes Schindelin git 3 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 24 repliesIn review
  2. v34 patches 4 repliesSuperseded
  3. v24 patches 13 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4Refactor skipping DOS drive prefixescompat/basename.c compat/mingw.c compat/mingw.h +2 more+28 -229 replies
2/4compat/basename: make basename() conform to POSIXcompat/basename.c+17 -32 replies
3/4Provide a dirname() function when NO_LIBGEN_H=YesPleasecompat/basename.c git-compat-util.h+46 -03 replies
4/4t0060: verify that basename() and dirname() work as expectedt/t0060-path-utils.sh test-path-utils.c+169 -07 replies

Reviews trailers per patch

None of the 4 patches has a Reviewed-by or Acked-by.

PatchRamsay JonesTorsten Bögershausen
SeriesPointed-out-by
1/4
2/4
3/4
4/4Derived-from-code-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/4] Ensure that we can build without libgen.h

This mini series adds a fall-back for the dirname() function that we use e.g. in git-am. This is necessary because not all platforms have a working libgen.h.

While at it, we ensure that our basename() drop-in conforms to the POSIX specifications.

In addition to Eric's style improvement, v4 also fixes the signature of skip_dos_drive_prefix() in the non-Windows case.

Johannes Schindelin (4):
Refactor skipping DOS drive prefixes compat/basename: make basename() conform to POSIX Provide a dirname() function when NO_LIBGEN_H=YesPlease
t0060: verify that basename() and dirname() work as expected

 compat/basename.c     |  66 ++++++++++++++++++--
 compat/mingw.c        |  14 ++---
 compat/mingw.h        |  10 ++-
 git-compat-util.h     |  10 +++
 path.c                |  14 ++---
 t/t0060-path-utils.sh |   3 +
 test-path-utils.c     | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 259 insertions(+), 24 deletions(-)

Interdiff vs v3:

diff --git a/compat/basename.c b/compat/basename.c index 0a2ed25..96bd953 100644
--- a/compat/basename.c
+++ b/compat/basename.c
@@ -29,20 +29,15 @@ char *gitbasename (char *path)

char *gitdirname(char *path)
{
+ static struct strbuf buf = STRBUF_INIT;
char *p = path, *slash = NULL, c;
int dos_drive_prefix;

if (!p)
return ".";

- if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p) {
- static struct strbuf buf = STRBUF_INIT;
-
-dot:
- strbuf_reset(&buf);
- strbuf_addf(&buf, "%.*s.", dos_drive_prefix, path);
- return buf.buf;
- }
+ if ((dos_drive_prefix = skip_dos_drive_prefix(&p)) && !*p)
+ goto dot;

/*
* POSIX.1-2001 says dirname("/") should return "/", and dirname("//")
@@ -64,8 +59,13 @@ dot:
slash = tentative;
}

- if (!slash)
- goto dot;
- *slash = '\0';
- return path;
+ if (slash) {
+ *slash = '\0';
+ return path;
+ }
+
+dot:
+ strbuf_reset(&buf);
+ strbuf_addf(&buf, "%.*s.", dos_drive_prefix, path);
+ return buf.buf;
}
diff --git a/git-compat-util.h b/git-compat-util.h
index 94f311a..5f72f1c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -338,7 +338,7 @@ static inline int git_has_dos_drive_prefix(const char *path)
#endif

#ifndef skip_dos_drive_prefix
-static inline int git_skip_dos_drive_prefix(const char **path) +static inline int git_skip_dos_drive_prefix(char **path)
{
return 0;
}

Signature · 1 line
2.6.3.windows.1.300.g1c25e49