Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.unix.wizards Subject: Re: Reading from stderr Summary: It depends on the level of I/O Message-ID: <8570@xanth.cs.odu.edu> Date: 20 Apr 89 16:47:53 GMT References: <5437@lynx.UUCP> <508@visdc.UUCP> <1094@vsi.COM> <330@hcr.UUCP> Distribution: na Organization: Old Dominion University, Norfolk, Va. Lines: 67 In article <330@hcr.UUCP> john@hcr.UUCP (John R. MacMillan) writes: >In article <1094@vsi.COM> friedl@vsi.UUCP writes: >|In article <508@visdc.UUCP>, jiii@visdc.UUCP (John E Van Deusen III) writes: >|> Since file >|> descriptors 0, 1, and 2 are all opened with oflag set to O_RDWR, ... >| >|An expansion here: stdin, stdout, and stderr are not opened independently. >|the terminal device is opened and the resulting fildes is dup-ed twice >|to yield stdout and stderr. > >But this isn't required of stdio, is it? I used systems where stderr >is write-only, and programs which read from it had to be fixed. I think there is a confusion here between high level I/O (stdin, stdout, stderr) and low level I/O (file descriptors 0, 1, 2). In any UNIX variant I have used, I have found that the previous posters were correct in saying that descriptors 0, 1, and 2 are originally created by the sequence open(..., O_RDWR); /* returns first available descriptor, 0 */ dup(0); /* returns first available descriptor, 1 */ dup(0); /* returns first available descriptor, 2 */ hence, read(2, ..., ...); should work. However, when the stdio FILEs are initialized, stdin is set for read-only (_IOREAD), stdout is set for write-only (_IOWRT), and stderr is set for write-only with no buffering (_IOWRT|_IONBF); hence getc(stderr); would not work. So it depends on the level of I/O you are using. You can check your own system's stdio setup with this short program: #include main() { int flag[3]; /* gotta get these before doing any stdio */ flag[0] = stdio->_flag; flag[1] = stdout->_flag; flag[2] = stderr->_flag; printf("stdin is \\%03o\n", flag[0]); printf("stdout is \\%03o\n", flag[1]); printf("stderr is \\%03o\n", flag[2]); return(0); } and comparing the results to the flag values #define'd in . As for absolute guarantees, "It works for me!". :-) -- Lloyd Kremer Brooks Financial Systems ...!uunet!xanth!brooks!lloyd Have terminal...will hack!