- Give PCI controllers lower unit numbers than legacy controllers.
[cake.git] / compiler / clib / mkdir.c
blob78f0db4d5615a9effdd34f68581faf830de4ca6c
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function mkdir().
6 */
8 #include <string.h>
9 #include <proto/dos.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include "__errno.h"
13 #include "__upath.h"
15 /*****************************************************************************
17 NAME */
18 #include <sys/stat.h>
20 int mkdir (
22 /* SYNOPSIS */
23 const char *path,
24 mode_t mode)
26 /* FUNCTION
27 Make a directory file
29 INPUTS
30 path - the path of the directory being created
31 mode - the permission flags for the directory
33 RESULT
34 0 on success or -1 on errorr.
36 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
44 chmod(), stat(), umask()
46 INTERNALS
48 ******************************************************************************/
51 BPTR lock;
52 char *apath;
54 if (!path) /*safety check */
56 errno = EFAULT;
57 return -1;
60 apath = (char*) __path_u2a(path);
61 if (!apath)
62 return -1;
64 /* Duplicate apath to avoid modifying function argument if !__upath */
65 apath = strdup(apath);
66 if (!apath)
68 errno = ENOMEM;
69 return -1;
72 /* Remove possible trailing / to avoid problems in handlers */
73 if(strlen(apath) > 0 && apath[strlen(apath)-1] == '/')
74 apath[strlen(apath)-1] = '\0';
76 lock = CreateDir((STRPTR) apath);
77 free(apath);
79 if (!lock)
81 errno = IoErr2errno(IoErr());
82 return -1;
85 UnLock(lock);
87 return 0;