_mkdir C runtime library function might return unexpected error values

by APIJunkie 22. December 2009 08:05

mkdir is a C runtime library function that creates directories.

In contrary to what could be understood from the MSDN documentation:

“…On an error, the function returns –1 and sets errno as follows.EEXIST Directory was not created because dirname is the name of an existing file, directory, or device.ENOENT Path was not found.For more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.”

mkdir might return other error values. For example when calling mkdir on an existing directory the function might return EEXIST but can also return EACCES (permission denied). The function error results seem to differ according to user access permissions on the system. This has been tested on Windows 2003/Vista/7. For more information and portability issues check out this discussion about mkdir portability in Kernel trap.

·         Note that this discussion applies to Microsoft’s implementation of the C run time library.

Tags:

C++ | C | Microsoft | Portability

Comments

Comments are closed

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon