commit: 6e3032548ebadc45699644e33b1c06abe3362c9e
parent bf93db3a6eba9906740e9bc09d90741ef312cfce
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 26 Sep 2024 10:33:17 +0200
lib/mkdir: move to lib/lib_mkdir to avoid coverage filename conflict
Diffstat:
6 files changed, 68 insertions(+), 69 deletions(-)
diff --git a/Makefile b/Makefile
@@ -132,9 +132,9 @@ cmd/chmod: cmd/chmod.c lib/mode.c lib/symbolize_mode.c Makefile
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
$(CC) -std=c99 $(CFLAGS) -o $@ cmd/chmod.c lib/mode.c lib/symbolize_mode.c $(LDFLAGS) $(LDSTATIC)
-cmd/mkdir: cmd/mkdir.c lib/mode.c lib/mode.h lib/mkdir.c lib/mkdir.h Makefile
+cmd/mkdir: cmd/mkdir.c lib/mode.c lib/mode.h lib/lib_mkdir.c lib/lib_mkdir.h Makefile
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
- $(CC) -std=c99 $(CFLAGS) -o $@ cmd/mkdir.c lib/mode.c lib/mkdir.c $(LDFLAGS) $(LDSTATIC)
+ $(CC) -std=c99 $(CFLAGS) -o $@ cmd/mkdir.c lib/mode.c lib/lib_mkdir.c $(LDFLAGS) $(LDSTATIC)
cmd/mknod: cmd/mknod.c lib/mode.c Makefile
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
@@ -183,9 +183,9 @@ cmd/expr: cmd/expr.tab.c Makefile
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
$(CC) -std=c99 $(CFLAGS) -D_POSIX_C_SOURCE=200809L -o $@ cmd/expr.tab.c $(LDFLAGS) $(LDSTATIC)
-cmd/install: cmd/install.c lib/mode.c lib/user_group_parse.c lib/user_group_parse.h lib/fs.c lib/fs.h lib/mkdir.c lib/mkdir.h Makefile config.mk
+cmd/install: cmd/install.c lib/mode.c lib/user_group_parse.c lib/user_group_parse.h lib/fs.c lib/fs.h lib/lib_mkdir.c lib/lib_mkdir.h Makefile config.mk
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
- $(CC) -std=c99 $(CFLAGS) -o $@ cmd/install.c lib/mode.c lib/user_group_parse.c lib/fs.c lib/mkdir.c $(LDFLAGS) $(LDSTATIC)
+ $(CC) -std=c99 $(CFLAGS) -o $@ cmd/install.c lib/mode.c lib/user_group_parse.c lib/fs.c lib/lib_mkdir.c $(LDFLAGS) $(LDSTATIC)
cmd/mv: cmd/mv.c lib/consent.c lib/consent.h lib/fs.c lib/fs.h Makefile config.mk
$(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno}
diff --git a/cmd/install.c b/cmd/install.c
@@ -7,7 +7,7 @@
#define _DEFAULT_SOURCE // FreeBSD
#include "../lib/fs.h"
-#include "../lib/mkdir.h"
+#include "../lib/lib_mkdir.h"
#include "../lib/mode.h"
#include "../lib/user_group_parse.h"
@@ -27,7 +27,7 @@
bool preserve_times = false, create_directories = false;
-// See lib/mkdir.c
+// See lib/lib_mkdir.c
bool mkdir_parents_verbose = false;
mode_t mkdir_parents_filemask;
diff --git a/cmd/mkdir.c b/cmd/mkdir.c
@@ -4,8 +4,7 @@
#define _POSIX_C_SOURCE 200809L
-#include "../lib/mkdir.h"
-
+#include "../lib/lib_mkdir.h"
#include "../lib/mode.h"
#include <assert.h>
diff --git a/lib/lib_mkdir.c b/lib/lib_mkdir.c
@@ -0,0 +1,61 @@
+// utils-std: Collection of commonly available Unix tools
+// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+// SPDX-License-Identifier: MPL-2.0
+
+#define _POSIX_C_SOURCE 200809L
+
+#include "./lib_mkdir.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h> // PATH_MAX
+#include <stdio.h> // fprintf
+#include <string.h> // strlen, strerror
+#include <sys/stat.h> // mkdir
+
+int
+mkdir_parents(char *path, mode_t mode)
+{
+ assert(errno == 0);
+
+ for(int i = strlen(path) - 1; i >= 0; i--)
+ {
+ if(path[i] != '/') break;
+
+ path[i] = 0;
+ }
+
+ char parent[PATH_MAX] = "";
+ strncpy(parent, path, PATH_MAX);
+
+ for(int i = strlen(parent) - 1; i >= 0; i--)
+ {
+ if(parent[i] == '/') break;
+
+ parent[i] = 0;
+ }
+
+ if(path[0] == 0) return 0;
+
+ mode_t parent_mode = (S_IWUSR | S_IXUSR | ~mkdir_parents_filemask) & 0777;
+
+ if(mkdir_parents(parent, parent_mode) < 0) return -1;
+
+ assert(errno == 0);
+ if(mkdir(path, mode) < 0)
+ {
+ if(errno == EEXIST)
+ {
+ errno = 0;
+ return 0;
+ }
+
+ fprintf(stderr, "%s: error: Failed making directory '%s': %s\n", argv0, path, strerror(errno));
+ errno = 0;
+ return -1;
+ }
+
+ if(mkdir_parents_verbose) fprintf(stderr, "%s: Made directory: %s\n", argv0, path);
+
+ return 0;
+}
diff --git a/lib/mkdir.h b/lib/lib_mkdir.h
diff --git a/lib/mkdir.c b/lib/mkdir.c
@@ -1,61 +0,0 @@
-// utils-std: Collection of commonly available Unix tools
-// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
-// SPDX-License-Identifier: MPL-2.0
-
-#define _POSIX_C_SOURCE 200809L
-
-#include "./mkdir.h"
-
-#include <assert.h>
-#include <errno.h>
-#include <limits.h> // PATH_MAX
-#include <stdio.h> // fprintf
-#include <string.h> // strlen, strerror
-#include <sys/stat.h> // mkdir
-
-int
-mkdir_parents(char *path, mode_t mode)
-{
- assert(errno == 0);
-
- for(int i = strlen(path) - 1; i >= 0; i--)
- {
- if(path[i] != '/') break;
-
- path[i] = 0;
- }
-
- char parent[PATH_MAX] = "";
- strncpy(parent, path, PATH_MAX);
-
- for(int i = strlen(parent) - 1; i >= 0; i--)
- {
- if(parent[i] == '/') break;
-
- parent[i] = 0;
- }
-
- if(path[0] == 0) return 0;
-
- mode_t parent_mode = (S_IWUSR | S_IXUSR | ~mkdir_parents_filemask) & 0777;
-
- if(mkdir_parents(parent, parent_mode) < 0) return -1;
-
- assert(errno == 0);
- if(mkdir(path, mode) < 0)
- {
- if(errno == EEXIST)
- {
- errno = 0;
- return 0;
- }
-
- fprintf(stderr, "%s: error: Failed making directory '%s': %s\n", argv0, path, strerror(errno));
- errno = 0;
- return -1;
- }
-
- if(mkdir_parents_verbose) fprintf(stderr, "%s: Made directory: %s\n", argv0, path);
-
- return 0;
-}