Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/mkdir.html
2024-02-19 00:21:47 -05:00

238 lines
8.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>mkdir</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="mkdir"></a> <a name="tag_03_371"></a><!-- mkdir -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_371_01"></a>NAME</h4>
<blockquote>mkdir - make a directory</blockquote>
<h4><a name="tag_03_371_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/sys/stat.h.html">sys/stat.h</a>&gt;<br>
<br>
int mkdir(const char *</tt><i>path</i><tt>, mode_t</tt> <i>mode</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_371_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>mkdir</i>() function shall create a new directory with name <i>path</i>. The file permission bits of the new directory
shall be initialized from <i>mode</i>. These file permission bits of the <i>mode</i> argument shall be modified by the process'
file creation mask.</p>
<p>When bits in <i>mode</i> other than the file permission bits are set, the meaning of these additional bits is
implementation-defined.</p>
<p>The directory's user ID shall be set to the process' effective user ID. The directory's group ID shall be set to the group ID of
the parent directory or to the effective group ID of the process. Implementations shall provide a way to initialize the directory's
group ID to the group ID of the parent directory. Implementations may, but need not, provide an implementation-defined way to
initialize the directory's group ID to the effective group ID of the calling process.</p>
<p>The newly created directory shall be an empty directory.</p>
<p>If <i>path</i> names a symbolic link, <i>mkdir</i>() shall fail and set <i>errno</i> to [EEXIST].</p>
<p>Upon successful completion, <i>mkdir</i>() shall mark for update the <i>st_atime</i>, <i>st_ctime</i>, and <i>st_mtime</i>
fields of the directory. Also, the <i>st_ctime</i> and <i>st_mtime</i> fields of the directory that contains the new entry shall be
marked for update.</p>
</blockquote>
<h4><a name="tag_03_371_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>mkdir</i>() shall return 0. Otherwise, -1 shall be returned, no directory shall be created, and
<i>errno</i> shall be set to indicate the error.</p>
</blockquote>
<h4><a name="tag_03_371_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>mkdir</i>() function shall fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>Search permission is denied on a component of the path prefix, or write permission is denied on the parent directory of the
directory to be created.</dd>
<dt>[EEXIST]</dt>
<dd>The named file exists.</dd>
<dt>[ELOOP]</dt>
<dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd>
<dt>[EMLINK]</dt>
<dd>The link count of the parent directory would exceed {LINK_MAX}.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
The length of the <i>path</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
<dt>[ENOENT]</dt>
<dd>A component of the path prefix specified by <i>path</i> does not name an existing directory or <i>path</i> is an empty
string.</dd>
<dt>[ENOSPC]</dt>
<dd>The file system does not contain enough space to hold the contents of the new directory or to extend the parent directory of
the new directory.</dd>
<dt>[ENOTDIR]</dt>
<dd>A component of the path prefix is not a directory.</dd>
<dt>[EROFS]</dt>
<dd>The parent directory resides on a read-only file system.</dd>
</dl>
<p>The <i>mkdir</i>() function may fail if:</p>
<dl compact>
<dt>[ELOOP]</dt>
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd>
<dt>[ENAMETOOLONG]</dt>
<dd>
As a result of encountering a symbolic link in resolution of the <i>path</i> argument, the length of the substituted pathname
string exceeded {PATH_MAX}.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_371_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_371_06_01"></a>Creating a Directory</h5>
<p>The following example shows how to create a directory named <b>/home/cnd/mod1</b>, with read/write/search permissions for owner
and group, and with read/search permissions for others.</p>
<pre>
<tt>#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
<br>
int status;
...
status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_371_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_371_08"></a>RATIONALE</h4>
<blockquote>
<p>The <i>mkdir</i>() function originated in 4.2 BSD and was added to System V in Release 3.0.</p>
<p>4.3 BSD detects [ENAMETOOLONG].</p>
<p>The POSIX.1-1990 standard required that the group ID of a newly created directory be set to the group ID of its parent directory
or to the effective group ID of the creating process. FIPS 151-2 required that implementations provide a way to have the group ID
be set to the group ID of the containing directory, but did not prohibit implementations also supporting a way to set the group ID
to the effective group ID of the creating process. Conforming applications should not assume which group ID will be used. If it
matters, an application can use <a href="../functions/chown.html"><i>chown</i>()</a> to set the group ID after the directory is
created, or determine under what conditions the implementation will set the desired group ID.</p>
</blockquote>
<h4><a name="tag_03_371_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_371_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="umask.html"><i>umask</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/stat.h.html"><i>&lt;sys/stat.h&gt;</i></a>, <a href=
"../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_371_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 3. Included for alignment with the POSIX.1-1988 standard.</p>
</blockquote>
<h4><a name="tag_03_371_12"></a>Issue 6</h4>
<blockquote>
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> header is
removed.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> has been removed. Although <a
href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a> was required for conforming implementations of previous POSIX
specifications, it was not required for UNIX applications.</p>
</li>
<li>
<p>The [ELOOP] mandatory error condition is added.</p>
</li>
<li>
<p>A second [ENAMETOOLONG] is added as an optional error condition.</p>
</li>
</ul>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>The [ELOOP] optional error condition is added.</p>
</li>
</ul>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>