robertwessel2@yahoo.com
9/1/2011 8:28:00 AM
On Thu, 1 Sep 2011 00:23:41 -0700 (PDT), tm <thomas.mertes@gmx.at>
wrote:
>On 1 Sep., 08:25, Angel <angel+n...@spamcop.net> wrote:
>> On 2011-08-31, James Kuyper <jameskuy...@verizon.net> wrote:
>>
>> > On 08/31/2011 06:43 PM, tm wrote:
>>
>> > A fully portable C program cannot call popen() and has no way to be sure
>> > whether or not a stream that it opens is a FIFO. You'll get better
>> > answers to your questions in a newsgroup associated with the library
>> > that provides popen() (and select() and fileno(), and all of the other
>> > implementation-specific features referred to in your program).
>>
>> Those are POSIX functions, I would guess he is working on some brand of
>> Unix and would thus be better off in comp.unix.programmer.
>
>I am writing code for Unix and Windows, but my question
>is about a FILE *, which is standard C.
>
>When you call getc(aFile) two things can happen:
>
> 1. The character is already in the FILE buffer.
> In this case the char is returned from the FILE
> buffer and the read position of the FILE buffer
> is adjusted.
> 2. The FILE buffer is empty.
> In this case a block of e.g. 1024 characters
> is read from the underlying file descriptor
> into the FILE buffer. Afterwards the first
> character from the FILE buffer is returned.
>
>What I need is:
>Find out if the next getc() will use case 1 or case 2.
>
>Historically getc() was defined as macro.
>
>Essentially I need the condition used in the getc() macro.
>I could take it from there, but I want to support
>several compilers, libraries and operating systems.
>
>Thats the reason I ask for a portable solution, to
>find out the number of chars currently in a FILE buffer.
While what you've described is a common way getc(), and such, are
implemented, it is certainly not anything mandated by the standard.
And since the standard specifies no way to access any information
about the contents of the FILE buffer (assuming the implementation
actually has such a thing), there is no portable way to do that.
getc() *may* be a macro (it's not required), but even if it is, it
could just be a wrapper around fgetc().