LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2010, 09:22 AM   #1
vbx_wx
Member
 
Registered: Feb 2010
Posts: 181

Rep: Reputation: 16
mkdir() linux/windows


Code:
void Wsk::makeDir(string name)
{
       #ifdef LINUX
	mkdir(name.c_str() , S_IRWXU | S_IRWXG | S_IRWXO);
	#endif
	#ifdef WINDOWS
	mkdir(name.c_str());
	#endif
}
isnt this suppose to work both in linux and windows ? if i use ifdef linux,it doesnt work,but if i comment it,its working,why is that ?
 
Old 03-30-2010, 09:38 AM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
Code:
#ifdef WIN32
 #define WINDOWS
#elif WIN64
 #define WINDOWS
#endif
void Wsk::makeDir(string name)
{
#ifdef linux
	mkdir(name.c_str() , S_IRWXU | S_IRWXG | S_IRWXO);
#endif
#ifdef WINDOWS
	mkdir(name.c_str());
#endif
}
work for me

Last edited by troop; 03-30-2010 at 09:41 AM.
 
Old 03-30-2010, 11:05 AM   #3
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey,

the difference between your version and the working version is how 'linux' is written. The C compiler (and C preprocessor) work in case-sensitive mode, though 'linux' is not the same as 'LINUX'. By the way, the gcc compiler (at least my version 4.4.3) defines the following macros if compiled on Linux platforms:

#define __linux 1
#define __linux__ 1
#define __gnu_linux__ 1
#define linux 1

Hope that makes clear why your code only works if you comment out the #ifdef LINUX ...

- Andi -
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkdir -p ? shanenin Linux - Software 4 10-19-2011 11:41 AM
how to give options like '-v' for mkdir using system call mkdir() ? nehapawar Linux - Newbie 2 02-05-2010 02:13 AM
I don't know. mkdir? Bobzilla2639716495 Linux - General 15 12-03-2007 11:22 AM
Windows XP batch script - mkdir %date% creates spaces! Micro420 Programming 1 10-19-2006 02:55 AM
mkdir help ITJedi Linux - Software 1 05-14-2004 05:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration