mkpath_np.3   [plain text]


.\" Copyright (c) 2011 Apple Inc. All rights reserved.
.\" 
.\" @APPLE_LICENSE_HEADER_START@
.\" 
.\" This file contains Original Code and/or Modifications of Original Code
.\" as defined in and that are subject to the Apple Public Source License
.\" Version 2.0 (the 'License'). You may not use this file except in
.\" compliance with the License. Please obtain a copy of the License at
.\" http://www.opensource.apple.com/apsl/ and read it before using this
.\" file.
.\" 
.\" The Original Code and all software distributed under the License are
.\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
.\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
.\" Please see the License for the specific language governing rights and
.\" limitations under the License.
.\" 
.\" @APPLE_LICENSE_HEADER_END@
.\"
.Dd July 13, 2011
.Dt mkpath_np 3
.Os "Mac OS X"
.Sh NAME
.Nm mkpath_np
.Nd Auxiliary routine for efficiently creating paths
.Sh SYNOPSIS
.Fd #include <unistd.h>
.\"
.Ft int
.Fo mkpath_np
.Fa "const char * path"
.Fa "mode_t omode"
.Fc
.Sh DESCRIPTION
This routine allows the caller to create a path, including intermediate
directories.  It is equivalent to calling
.Xr mkdir 1
with the -p command line argument.
.Pp
Intermediate directories are created with permission bits of rwxrwxrwx (0777)
as modified by the current umask, plus write and search permission for the
owner.
.Pp
The leaf directory is created with permission bits of
.Fa omode
as modified by the current umask.
.Sh RETURN VALUES
A 0 return value indicates success.  If an error occurs, the return value is a
non-zero error code.  Note that EEXIST is returned iff the leaf directory
already exists and is a directory, so under certain circumstances, this error
value may not indicate a failure state.
.Pp
This routine does NOT modify errno.
.Sh ERRORS
Any error code that can be returned by
.Xr mkdir 2
can be returned by
.Fn mkpath_np ,
but
.Fn mkpath_np
will return the error code rather than setting errno.
.Bl -tag -width Er
.\" ==========
.It Bq Er ENOTDIR
A component of the path is not a directory (in contrast to
.Xr mkdir 2
which returns this based on the path prefix rather than the path).
.\" ==========
.It Bq Er EEXIST
The path already exists and is a directory.
.El
.Sh HISTORY
This function first appeared in
iOS 5.0.
.Sh SEE ALSO
.Xr mkdir 1 ,
.Xr chmod 2 ,
.Xr mkdir 2