git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Ignore trailing slash in mkdir() on platforms that can't deal with this

From
Joachim Schmitz <jojo@schmitz-digital.de>
Date
Aug 24, 2012, 10:31 UTC
Message-ID
<003101cd81e3$90574490$b105cdb0$@schmitz-digital.de>
Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>
---
 compat/mkdir.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 compat/mkdir.c
diff --git a/compat/mkdir.c b/compat/mkdir.c
new file mode 100644
index 0000000..9e253fb
--- /dev/null
+++ b/compat/mkdir.c
@@ -0,0 +1,24 @@
+#include "../git-compat-util.h"
+#undef mkdir
+
+/* for platforms that can't deal with a trailing '/' */
+int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode)
+{
+	int retval;
+	char *tmp_dir = NULL;
+	size_t len = strlen(dir);
+
+	if (len && dir[len-1] == '/') {
+		if ((tmp_dir = strdup(dir)) == NULL)
+			return -1;
+		tmp_dir[len-1] = '\0';
+	}
+	else
+		tmp_dir = (char *)dir;
+
+	retval = mkdir(tmp_dir, mode);
+	if (tmp_dir != dir)
+		free(tmp_dir);
+
+	return retval;
+}
-- 
1.7.12
Next: Junio C Hamano
Message 1 of 3 in “Ignore trailing slash in mkdir() on platforms that can't deal with this”
  1. 1/2 Ignore trailing slash in mkdir() on platforms that can't deal with thisJoachim Schmitz, Aug 24, 2012
  2. Junio C HamanoAug 24, 2012
  3. Joachim SchmitzAug 24, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.