mkdir()

Create a subdirectory

Synopsis:

#include <sys/types.h>
#include <sys/stat.h>

int mkdir( const char *path,
           mode_t mode );

Since:

BlackBerry 10.0.0

Arguments:

path
The name of the directory that you want to create.
mode
The permissions for the directory, modified by the process's file-creation mask (see umask()).

The access permissions for the file or directory are specified as a combination of bits defined in the <sys/stat.h> header file. For more information, see " Access permissions " in the documentation for stat().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mkdir() function creates a new subdirectory named path. The path can be relative to the current working directory or it can be an absolute path name.

Not all filesystems support the creation of directories. For example, /dev/shmem (which really isn't a filesystem but looks like one) doesn't. For more information, see the Working with Filesystems chapter of the BlackBerry 10 OS User's Guide.

The directory's owner ID is set to the process's effective user ID. The directory's group ID is set to the group ID of the parent directory (if the parent set-group ID bit is set) or to the process's effective group ID.

The newly created directory is empty.

The following bits, in addition to file permission bits, behave as follows:

S_ISGID
Files and directories created within this directory have the group ID of this directory instead of the group ID of the process creating the file or directory.
S_ISVTX
Files can be removed or renamed only if one or more of the following is true:
  • The user owns the file.
  • The user owns the directory.
  • The file is writable by the user.
  • The user is privileged.

The mkdir() function marks the st_atime, st_ctime, and st_mtime fields of the directory for update. Also, the st_ctime and st_mtime fields of the parent directory are also updated.

Returns:

0, or -1 if an error occurs ( errno is set).

Errors:

EACCES
Search permission is denied for a component of path, or write permission is denied on the parent directory of path.
EEXIST
The directory named by path already exists.
ELOOP
Too many levels of symbolic links.
EMLINK
The link count of the parent directory would exceed LINK_MAX.
ENAMETOOLONG
The length of path exceeds PATH_MAX, or a pathname component is longer than NAME_MAX.
ENOENT
A pathname component in the specified path does not exist, or path is an empty string.
ENOSPC
The filesystem does not contain enough space to hold the contents of the new directory or to extend the parent directory.
ENOSYS
This function is not supported for this path.
ENOTDIR
A component of path is not a directory.
EROFS
The parent directory resides on a read-only filesystem.

Examples:

To make a new directory called /src in /hd:

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>

int main( void )
{
    (void)mkdir( "/hd/src",
                 S_IRWXU |
                 S_IRGRP | S_IXGRP |
                 S_IROTH | S_IXOTH );

    return EXIT_SUCCESS;
}

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus