1 |
vapier 11/03/02 01:18:02 |
2 |
|
3 |
Modified: xmkdir.c |
4 |
Log: |
5 |
optimize a bit, and make sure we dont need a trailing slash for the last dir component |
6 |
|
7 |
Revision Changes Path |
8 |
1.2 portage-utils/libq/xmkdir.c |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.2&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.2&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?r1=1.1&r2=1.2 |
13 |
|
14 |
Index: xmkdir.c |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmkdir.c,v |
17 |
retrieving revision 1.1 |
18 |
retrieving revision 1.2 |
19 |
diff -u -r1.1 -r1.2 |
20 |
--- xmkdir.c 23 Feb 2011 08:59:45 -0000 1.1 |
21 |
+++ xmkdir.c 2 Mar 2011 01:18:02 -0000 1.2 |
22 |
@@ -3,17 +3,25 @@ |
23 |
{ |
24 |
char *_p, *p, *s; |
25 |
|
26 |
+ /* Assume that most of the time, only the last element |
27 |
+ * is missing. So if we can mkdir it right away, bail. */ |
28 |
+ if (mkdir(path, mode) == 0 || errno == EEXIST) |
29 |
+ return 0; |
30 |
+ |
31 |
+ /* Build up the whole tree */ |
32 |
_p = p = xstrdup(path); |
33 |
|
34 |
- while (1) { |
35 |
+ while (*p) { |
36 |
/* Skip duplicate slashes */ |
37 |
while (*p == '/') |
38 |
++p; |
39 |
|
40 |
/* Find the next path element */ |
41 |
s = strchr(p, '/'); |
42 |
- if (!s) |
43 |
+ if (!s) { |
44 |
+ mkdir(_p, mode); |
45 |
break; |
46 |
+ } |
47 |
|
48 |
/* Make it */ |
49 |
*s = '\0'; |