Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

14.8 Creating Directories

Directories are created with the mkdir function. (There is also a shell command mkdir which does the same thing.)

— Function: int mkdir (const char *filename, mode_t mode)

The mkdir function creates a new, empty directory with name filename.

The argument mode specifies the file permissions for the new directory file. See Permission Bits, for more information about this.

A return value of 0 indicates successful completion, and -1 indicates failure. In addition to the usual file name syntax errors (see File Name Errors), the following errno error conditions are defined for this function:

EACCES
Write permission is denied for the parent directory in which the new directory is to be added.
EEXIST
A file named filename already exists.
EMLINK
The parent directory has too many links (entries).

Well-designed file systems never report this error, because they permit more links than your disk could possibly hold. However, you must still take account of the possibility of this error, as it could result from network access to a file system on another machine.

ENOSPC
The file system doesn't have enough room to create the new directory.
EROFS
The parent directory of the directory being created is on a read-only file system and cannot be modified.

To use this function, your program should include the header file sys/stat.h.


 
 
  Published under the terms of the GNU General Public License Design by Interspire