Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1363575970.15703.20@driftwood>
Date: Sun, 17 Mar 2013 22:06:10 -0500
From: Rob Landley <rob@...dley.net>
To: musl@...ts.openwall.com
Cc: musl@...ts.openwall.com
Subject: Re: question: hard-coded file descriptors in
 stdin/stdout/stderr

On 03/14/2013 11:18:53 AM, Zvi Gilboa wrote:
> Greetings,
> 
> I just noticed that the file descriptors in stdin.c, stdout.c, and  
> stderr.c do not use the #defines from <unistd.h> (namely  
> STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO), but are rather  
> hard-coded (as 0, 1, and 2 respectively).

Because these have been constant values since 1969, were adopted by DOS  
in 1983, and the numerical values are SPECIFIED BY POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html

   STDIN_FILENO - Standard input value, stdin. Its value is 0.
   STDOUT_FILENO - Standard output value, stdout. Its value is 1.
   STDERR_FILENO - Standard error value, stderr. Its value is 2.

> I was therefore wondering whether there was a special reason for that?

Because MUSL is simple and using a macro to specify a constant that's  
standardized by posix, has been stable for over 40 years, and is  
regularly used on the command line, is pointless?

> With POSIX systems this would normally not be an issue, however there  
> are still some
> systems out there with standard file descriptor numbers which are  
> different...

Posix specifies the value of the constant. Supporting systems that  
violate posix was not, last I checked, part of musl's goals?

> On that same note: wouldn't it make sense to slightly modify unistd.h  
> so that it
> first checks whether STDIN_FILENO, etc. have already been defined?   
> That would allow
> a system with different standard file descriptor numbers to define  
> them in one of
> the /arch headers, yet enable the default for systems that use the  
> "normal" numbers.
> The relevant section would then read:

What system are you referring to? "There are systems" means what,  
exactly>

Not Linux, not Mac, not Android, not iOS... what are you referring to?

Rob

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.