tangled
alpha
login
or
join now
jcs.org
/
openbsd-src
0
fork
atom
jcs's openbsd hax
openbsd
0
fork
atom
overview
issues
pulls
pipelines
Sync code with the original from mkdir(1). OK benno@
claudio
4 years ago
41ffc556
e107519e
+17
-11
1 changed file
expand all
collapse all
unified
split
usr.bin
rsync
mkpath.c
+17
-11
usr.bin/rsync/mkpath.c
reviewed
···
1
1
-
/* $OpenBSD: mkpath.c,v 1.4 2019/05/08 21:30:11 benno Exp $ */
1
1
+
/* $OpenBSD: mkpath.c,v 1.5 2021/05/17 11:52:10 claudio Exp $ */
2
2
/*
3
3
* Copyright (c) 1983, 1992, 1993
4
4
* The Regents of the University of California. All rights reserved.
···
46
46
{
47
47
struct stat sb;
48
48
char *slash;
49
49
-
int done = 0;
49
49
+
int done;
50
50
51
51
slash = path;
52
52
53
53
-
while (!done) {
53
53
+
for (;;) {
54
54
slash += strspn(slash, "/");
55
55
slash += strcspn(slash, "/");
56
56
57
57
done = (*slash == '\0');
58
58
*slash = '\0';
59
59
60
60
-
if (stat(path, &sb)) {
61
61
-
if (errno != ENOENT || (mkdir(path, 0777) &&
62
62
-
errno != EEXIST)) {
63
63
-
ERR("%s: stat", path);
60
60
+
if (mkdir(path, 0777) != 0) {
61
61
+
int mkdir_errno = errno;
62
62
+
63
63
+
if (stat(path, &sb) == -1) {
64
64
+
/* Not there; use mkdir()s errno */
65
65
+
errno = mkdir_errno;
64
66
return (-1);
65
67
}
66
66
-
} else if (!S_ISDIR(sb.st_mode)) {
67
67
-
errno = ENOTDIR;
68
68
-
ERR("%s: stat", path);
69
69
-
return (-1);
68
68
+
if (!S_ISDIR(sb.st_mode)) {
69
69
+
/* Is there, but isn't a directory */
70
70
+
errno = ENOTDIR;
71
71
+
return (-1);
72
72
+
}
70
73
}
74
74
+
75
75
+
if (done)
76
76
+
break;
71
77
72
78
*slash = '/';
73
79
}