]> cygwin.com Git - cygwin-apps/setup.git/blob - mkdir.cc
Use parse_filename method to parse filenames throughout. Use get_root_dir to
[cygwin-apps/setup.git] / mkdir.cc
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 *
14 */
15
16 /* see mkdir.h */
17
18 static char *cvsid = "\n%%% $Id$\n";
19
20 #include "win32.h"
21
22 #include <stdio.h>
23
24 #include "mkdir.h"
25
26 int
27 mkdir_p (int isadir, const char *in_path)
28 {
29 char saved_char, *slash = 0;
30 char *c;
31 DWORD d, gse;
32 char path[strlen (in_path) + 1];
33 strcpy (path, in_path);
34
35 d = GetFileAttributes (path);
36 if (d != 0xffffffff && d & FILE_ATTRIBUTE_DIRECTORY)
37 return 0;
38
39 if (isadir)
40 {
41 if (CreateDirectory (path, 0))
42 return 0;
43 gse = GetLastError ();
44 if (gse != ERROR_PATH_NOT_FOUND && gse != ERROR_FILE_NOT_FOUND)
45 {
46 if (gse == ERROR_ALREADY_EXISTS)
47 {
48 fprintf (stderr, "warning: deleting \"%s\" so I can make a directory there\n",
49 path);
50 if (DeleteFileA (path))
51 return mkdir_p (isadir, path);
52 }
53 return 1;
54 }
55 }
56
57 for (c = path; *c; c++)
58 {
59 if (*c == ':')
60 slash = 0;
61 if (*c == '/' || *c == '\\')
62 slash = c;
63 }
64
65 if (!slash)
66 return 0;
67
68 saved_char = *slash;
69 *slash = 0;
70 if (mkdir_p (1, path))
71 {
72 *slash = saved_char;
73 return 1;
74 }
75 *slash = saved_char;
76
77 if (!isadir)
78 return 0;
79
80 return mkdir_p (isadir, path);
81 }
This page took 0.038023 seconds and 5 git commands to generate.