tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / compiler / posixc / mkdir.c
blobb661286a13fa57d4c34758c96cd8199232e97e29
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function mkdir().
6 */
8 #include <string.h>
9 #include <proto/dos.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include "__upath.h"
14 /*****************************************************************************
16 NAME */
17 #include <sys/stat.h>
19 int mkdir (
21 /* SYNOPSIS */
22 const char *path,
23 mode_t mode)
25 /* FUNCTION
26 Make a directory file
28 INPUTS
29 path - the path of the directory being created
30 mode - the permission flags for the directory
32 RESULT
33 0 on success or -1 on errorr.
35 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 chmod(), stat(), umask()
45 INTERNALS
47 ******************************************************************************/
50 BPTR lock;
51 char *apath;
53 if (!path) /*safety check */
55 errno = EFAULT;
56 return -1;
59 apath = (char*) __path_u2a(path);
60 if (!apath)
61 return -1;
63 /* Duplicate apath to avoid modifying function argument if !__upath */
64 apath = strdup(apath);
65 if (!apath)
67 errno = ENOMEM;
68 return -1;
71 /* Remove possible trailing / to avoid problems in handlers */
72 if(strlen(apath) > 0 && apath[strlen(apath)-1] == '/')
73 apath[strlen(apath)-1] = '\0';
75 lock = CreateDir((STRPTR) apath);
76 free(apath);
78 if (!lock)
80 errno = __stdc_ioerr2errno(IoErr());
81 return -1;
84 UnLock(lock);
86 return 0;