TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: William McBrine
date: 2003-07-21 10:26:10
subject: Re: Creating a directory

-=> Neil Heller wrote to All <=-

 NH> Is there a "standard" way of dealing with directory creation?

mkdir() is POSIX. That's about as standard as you can hope for with this 
kind of function. (Indeed, I'm surprised that something like rename() made 
it into ANSI.) But, you'll still have to use conditional code to make it 
completely portable. Here's mine:


int mymkdir(const char *pathname)
{
#ifdef HAS_UNISTD
        return mkdir(pathname, S_IRWXU);
#else
        return mkdir(pathname);
#endif
}


"HAS_UNISTD", in turn, was defined this way:


#ifndef __TURBOC__
# define HAS_UNISTD
#endif


which allows mymkdir() to work on Borland/Turbo C as well as POSIX systems; 
I can't vouch for any others (e.g., Microsoft). "unistd.h" is the standard 
header for POSIX functions, where they're available.

... He who opens a school door, closes a prison - Victor Hugo
--- MultiMail/Linux v0.45
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 633/267 270
@PATH: 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.