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