]> cygwin.com Git - cygwin-apps/setup.git/blame - mkdir.cc
* net.cc (do_net): Default to direct download.
[cygwin-apps/setup.git] / mkdir.cc
CommitLineData
23c9e63c
DD
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
8507f105
DD
18static char *cvsid = "\n%%% $Id$\n";
19
23c9e63c
DD
20#include "win32.h"
21
22#include <stdio.h>
23
24#include "mkdir.h"
25
26int
27mkdir_p (int isadir, char *path)
28{
29 char saved_char, *slash = 0;
30 char *c;
31 DWORD d, gse;
32
33 d = GetFileAttributes (path);
34 if (d != 0xffffffff && d & FILE_ATTRIBUTE_DIRECTORY)
35 return 0;
36
37 if (isadir)
38 {
39 if (CreateDirectory (path, 0))
40 return 0;
41 gse = GetLastError ();
89725f30 42 if (gse != ERROR_PATH_NOT_FOUND && gse != ERROR_FILE_NOT_FOUND)
23c9e63c
DD
43 {
44 if (gse == ERROR_ALREADY_EXISTS)
45 {
1fd6d0a2
DD
46 fprintf (stderr, "warning: deleting \"%s\" so I can make a directory there\n",
47 path);
23c9e63c 48 if (DeleteFileA (path))
1fd6d0a2 49 return mkdir_p (isadir, path);
23c9e63c
DD
50 }
51 return 1;
52 }
53 }
54
55 for (c=path; *c; c++)
56 {
57 if (*c == ':')
58 slash = 0;
59 if (*c == '/' || *c == '\\')
60 slash = c;
61 }
62
63 if (!slash)
64 return 0;
65
66 saved_char = *slash;
67 *slash = 0;
68 if (mkdir_p (1, path))
69 {
70 *slash = saved_char;
71 return 1;
72 }
73 *slash = saved_char;
74
75 if (!isadir)
76 return 0;
77
78 return mkdir_p (isadir, path);
79}
This page took 0.030069 seconds and 5 git commands to generate.