Pabbisetty.henr@xerox.com (Nagesh Pabbisetty) (11/15/88)
Here is an easy one for the wizards:
On Sun3, /usr/include/stdio reads as follows:
extern struct _iobuf {
int _cnt;
unsigned char *_ptr;
unsigned char *_base;
int _bufsiz;
short _flag;
char _file; /* should be short */
} _iob[];
Could someone tell me
1."what" is stored in each of these fields? OR
2. What is their significance.
Thanks....
Nagesh
henry@utzoo.uucp (Henry Spencer) (11/16/88)
In article <17521@adm.BRL.MIL> Pabbisetty.henr@xerox.com (Nagesh Pabbisetty) writes: >Could someone tell me > 1."what" is stored in each of these fields? OR > 2. What is their significance. I assume you realize that (a) you aren't supposed to care, and (b) it is all very implementation-dependent and subject to change? -- Sendmail is a bug, | Henry Spencer at U of Toronto Zoology not a feature. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
jsdy@hadron.UUCP (Joseph S. D. Yao) (11/22/88)
In article <17521@adm.BRL.MIL> Pabbisetty.henr@xerox.com (Nagesh Pabbisetty) writes: >Could someone tell me > 1."what" is stored in each of these fields? OR > 2. What is their significance. >Nagesh Henry is absolutely right. Their definition and meaning may change at any moment, and you should not need to use them directly. That's the whole point of "information hiding" within the stdio module. However, (a) curiosity is legitimate, and (b) there are ways to use them even through the protective screen of the stdio module. >extern struct _iobuf { > int _cnt; The number of characters read and not transferred to the program, or transferred from the program and not written. Only to be set by getc()/_filbuf() or putc()/_flsbuf(), or their near and dear relatives. > unsigned char *_ptr; Pointer to the next byte to be gotten or empty space into which to be written. Same caveats as above. > unsigned char *_base; Pointer to the first element of the I/O buffer proper. This can be set by setbuf(). Non-standard interfaces to extend this functionality include setvbuf(), setbuffer(), and setlinebuf(). (Perhaps I should say non-uniform: these are the ones that, unlike setbuf(), are not yet universal to all versions of stdio.) > int _bufsiz; This is the size of the buffer, in those versions of stdio that allow the buffer to be a size different from BUFSIZ. Warning: use of different buffer sizes may be incompletely implemented in your version. I think it was System V Release 2.0 Version 2 in which they forgot to fix fwrite(). I may be wrong. (The above identification changed at least once before getting to you.) This is set by one of the non-uniform variants of setbuf(). Once set, don't muck with it except as specified in your stdio interface definition (or setbuf manual entry). > short _flag; These flags tell whether the buffer is read, write, or read/write; buffered, unbuffered, or (where relevant) line-buffered; whether an error or EOF has been seen; and other necessary information, per implementation. If you value the sanity of your program, you will usually not mess with them. If you want to know what flags were advertised (which is often the same as the set that is used in your implementation), grep "_IO" stdio.h. The two legitimate interfaces to this are macros or functions to test for EOF and error: feof() and ferror(). > char _file; /* should be short */ This is the Unix file descriptor - obviously meaningless if this is not a Unix-like system. (Yes, I know about Suns.) If you really, really need to meddle with it, such as for stty() or one of the few other Unix functions for which there is not a stdio equivalent, you can access it via fileno(). You set it via fopen(), or from an already existing Unix file descriptor by fdopen(), which is fairly uniformly implemented by now. (It wasn't, in earlier versions.) >} _iob[]; Joe Yao jsdy@hadron.COM (not yet domainised) hadron!jsdy@{uunet.UU.NET,dtix.ARPA,decuac.DEC.COM} arinc,att,avatar,blkcat,cos,decuac,dtix,\ ecogong,empire,gong,grebyn,inco,insight, \!hadron!jsdy kcwc,lepton,netex,netxcom,phw5,rlgvax, / seismo,sms,smsdpg,sundc,uunet /