1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                                 M K D I R                                *
6  *                                                                          *
7  *                          C Implementation File                           *
8  *                                                                          *
9  *             Copyright (C) 2002-2019, Free Software Foundation, Inc.      *
10  *                                                                          *
11  * GNAT is free software;  you can  redistribute it  and/or modify it under *
12  * terms of the  GNU General Public License as published  by the Free Soft- *
13  * ware  Foundation;  either version 3,  or (at your option) any later ver- *
14  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16  * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
17  *                                                                          *
18  * As a special exception under Section 7 of GPL version 3, you are granted *
19  * additional permissions described in the GCC Runtime Library Exception,   *
20  * version 3.1, as published by the Free Software Foundation.               *
21  *                                                                          *
22  * You should have received a copy of the GNU General Public License and    *
23  * a copy of the GCC Runtime Library Exception along with this program;     *
24  * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
25  * <http://www.gnu.org/licenses/>.                                          *
26  *                                                                          *
27  * GNAT was originally developed  by the GNAT team at  New York University. *
28  * Extensive contributions were provided by Ada Core Technologies Inc.      *
29  *                                                                          *
30  ****************************************************************************/
31 
32 #ifdef __vxworks
33 #include "vxWorks.h"
34 #include <version.h>
35 #endif /* __vxworks */
36 
37 #ifdef IN_RTS
38 #include "runtime.h"
39 #include <sys/stat.h>
40 #else
41 #include "config.h"
42 #include "system.h"
43 #endif
44 
45 #ifdef __MINGW32__
46 #include "mingw32.h"
47 #include <windows.h>
48 #ifdef MAXPATHLEN
49 #define GNAT_MAX_PATH_LEN MAXPATHLEN
50 #else
51 #define GNAT_MAX_PATH_LEN 256
52 #endif
53 #endif
54 
55 #include "adaint.h"
56 
57 /*  This function provides a portable binding to the mkdir function.  */
58 
59 int
__gnat_mkdir(char * dir_name,int encoding ATTRIBUTE_UNUSED)60 __gnat_mkdir (char *dir_name, int encoding ATTRIBUTE_UNUSED)
61 {
62 #if defined (__vxworks)
63 
64   /* Pretend that the system mkdir is posix compliant even though it
65      sometimes is not, not expecting the second argument in some
66      configurations (e.g. vxworks 653 2.2, difference from 2.5). The
67      second actual argument will just be ignored in this case.  */
68 
69   typedef int posix_mkdir (const char * name, mode_t mode);
70 
71   posix_mkdir * vxmkdir = (posix_mkdir *)&mkdir;
72   return vxmkdir (dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
73 
74 #elif defined (__MINGW32__)
75   TCHAR wname [GNAT_MAX_PATH_LEN + 2];
76 
77   if (encoding == Encoding_Unspecified)
78     S2WSC (wname, dir_name, GNAT_MAX_PATH_LEN);
79   else if (encoding == Encoding_UTF8)
80     S2WSU (wname, dir_name, GNAT_MAX_PATH_LEN);
81   else
82     S2WS (wname, dir_name, GNAT_MAX_PATH_LEN);
83 
84   return _tmkdir (wname);
85 #else
86   return mkdir (dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
87 #endif
88 }
89