]> git.sesse.net Git - rdpsrv/blob - Xserver/config/util/mkdirhier.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / config / util / mkdirhier.c
1 /* $TOG: mkdirhier.c /main/2 1997/06/05 18:09:26 kaleb $ */
2 /*
3
4 Copyright (C) 1996 X Consortium
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall
26 not be used in advertising or otherwise to promote the sale, use or
27 other dealings in this Software without prior written authorization
28 from the X Consortium.
29
30 */
31
32 /*
33  * Simple mkdirhier program for Windows NT
34  */
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <direct.h>
38 #include <stdlib.h>\r
39 #include <string.h>
40
41 char *
42 next_sep(char *path)
43 {
44     while (*path)
45         if (*path == '/' || *path == '\\')
46             return path;
47         else
48             path++;
49     return NULL;
50 }
51
52 int
53 main(int argc, char *argv[])
54 {
55     char *dirname, *next, *prev;
56     char buf[1024];
57     struct _stat sb;
58
59     if (argc < 2)
60         exit(1);
61     dirname = argv[1];
62
63     prev = dirname;
64     while (next = next_sep(prev)) {
65         strncpy(buf, dirname, next - dirname);
66         buf[next - dirname] = '\0';
67         /* if parent dir doesn't exist yet create it */
68         if (_stat(buf, &sb))
69             _mkdir(buf);        /* no error checking to avoid barfing on C: */
70         prev = next + 1;
71     }
72     if (_mkdir(dirname) == -1) {
73         perror("mkdirhier failed");
74         exit(1);
75     }
76     exit(0);
77 }