stagit

fix dirname for glibc

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 426d80c parent: 360728d
1 files changed, 27 insertions(+), 2 deletions(-)
Murmoms.c+27-2
M · urmoms.c +27, -2
 1@@ -140,6 +140,27 @@ xmlencode(FILE *fp, const char *s, size_t len)
 2 	}
 3 }
 4 
 5+/* Some implementations of dirname(3) return a pointer to a static
 6+ * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
 7+ * This is a wrapper function that is compatible with both versions.
 8+ * The program will error out if dirname(3) failed, this can only happen
 9+ * with the OpenBSD version. */
10+char *
11+xdirname(const char *path)
12+{
13+	char *p, *b;
14+
15+	if (!(p = strdup(path)))
16+		err(1, "strdup");
17+	if (!(b = dirname(p)))
18+		err(1, "basename");
19+	if (!(b = strdup(b)))
20+		err(1, "strdup");
21+	free(p);
22+
23+	return b;
24+}
25+
26 /* Some implementations of basename(3) return a pointer to a static
27  * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX).
28  * This is a wrapper function that is compatible with both versions.
29@@ -571,12 +592,16 @@ writeblob(git_object *obj, const char *filename, git_off_t filesize)
30 {
31 	char fpath[PATH_MAX];
32 	char tmp[PATH_MAX] = "";
33-	char *p;
34+	char *d, *p;
35 	FILE *fp;
36 
37 	snprintf(fpath, sizeof(fpath), "file/%s.html", filename);
38-	if (mkdirp(dirname(fpath)))
39+	d = xdirname(fpath);
40+	if (mkdirp(d)) {
41+		free(d);
42 		return 1;
43+	}
44+	free(d);
45 
46 	p = fpath;
47 	while (*p) {