annotate netinstall/mkdir.cc @ 981:0205cafe98ff

[xemacs-hg @ 2002-08-30 08:25:48 by youngs] Don't look now, but 21.5.9 is on its way out the door! Don't forget what good 'ol Ma used to say... "Eat your brussels sprouts, little Johnny, so you can grow up big and strong."
author youngs
date Fri, 30 Aug 2002 08:26:22 +0000
parents 3078fd1074e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
1 /*
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
2 * Copyright (c) 2000, Red Hat, Inc.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
3 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
7 * (at your option) any later version.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
8 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
9 * A copy of the GNU General Public License can be found at
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
10 * http://www.gnu.org/
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
11 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
12 * Written by DJ Delorie <dj@cygnus.com>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
13 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
14 */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
15
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
16 /* see mkdir.h */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
17
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
18 #include "win32.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
19 #include <stdio.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
20 #include "mkdir.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
21
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
22 int
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
23 mkdir_p (int isadir, char *path)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
24 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
25 char saved_char, *slash = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
26 char *c;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
27 DWORD d, gse;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
28
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
29 d = GetFileAttributes (path);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
30 if (d != 0xffffffff && d & FILE_ATTRIBUTE_DIRECTORY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
31 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
32
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
33 if (isadir)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
34 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
35 if (CreateDirectory (path, 0))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
36 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
37 gse = GetLastError ();
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
38 if (gse != ERROR_PATH_NOT_FOUND && gse != ERROR_FILE_NOT_FOUND)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
39 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
40 if (gse == ERROR_ALREADY_EXISTS)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
41 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
42 fprintf (stderr, "warning: deleting \"%s\" so I can make a directory there\n",
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
43 path);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
44 if (DeleteFileA (path))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
45 return mkdir_p (isadir, path);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
46 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
47 return 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
48 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
49 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
50
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
51 for (c=path; *c; c++)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
52 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
53 if (*c == ':')
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
54 slash = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
55 if (*c == '/' || *c == '\\')
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
56 slash = c;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
57 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
58
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
59 if (!slash)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
60 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
61
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
62 saved_char = *slash;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
63 *slash = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
64 if (mkdir_p (1, path))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
65 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
66 *slash = saved_char;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
67 return 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
68 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
69 *slash = saved_char;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
70
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
71 if (!isadir)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
72 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
73
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
74 return mkdir_p (isadir, path);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
75 }