2

here it is, the FILE stream implementation in C :

typedef struct 
{
 short level ;
 short token ;
 short bsize ;
 char fd ;
 unsigned flags ;
 unsigned char hold ;
 unsigned char *buffer ;
 unsigned char * curp ;
 unsigned istemp; 
}FILE ;

I really don't know what all of these are for, and I wonder if the buffer contains the full file or not. If not, how does mister C know where to find the rest of the file ?

1 Answers1

3

You are not supposed to know. FILE is an 'opaque' structure and you must not mess with its fields. Probably, it does not contain the full file, and the associated functions read it as you request data. To know more, you could read the source code for the f* functions, but don't assume that they will work the same in other versions of the library, or in other libraries.

Cecilio Pardo
  • 1,717
  • 10
  • 13
  • I ask because I have a school project about making a filesystem on a fake disk (stored in a file)... In fact it's for DIR exactly. I can read the whole dir and fill a struct with a buffer and an offset, but this is not optimum, and since directory (or file contents) might not be stored consecutively. I still could store adress of the next block where to find datas in the struct, but that means the implementation depends of the filesystem... So I was wondering how does the real FILE and DIR does besides its opacity... – Nicolas Scotto Di Perto Jan 05 '16 at 11:40
  • Well, the FILE functions do not deal with that directly. That's done deeper in the OS. But you already got the idea: ordered blocks, with a fixed size. That's the way to go. – Cecilio Pardo Jan 05 '16 at 11:45