Questions about file handling

Hi, im wondering what is commonly used as file handlig.

Is the C stdio.h the way to go with file handling or are there any other commonly used File handling libraries?

Should you write your own file handling system and how would you go about doing so?

What are bigger studios using when it comes to this subject?

Are there any alternatives to stdio.h if you want to program in C.

Edited by C_Worm on Reason: Initial post
For game engines, people tend to avoid the CRT / STL.
The reason is that most of the time they're too general, thus sub-optimal for the given situation.

If you're using windows, you want to use CreateFileA, ReadFile, etc.

Every situation has its own specifics though, so depending on that you may want to:
- Use overlapped IO.
- Memory Map the file.

Here's the relevant episode where Casey explains things in more depth.
https://hero.handmade.network/episode/code/day152

As for libraries, it depends on what you want to do exactly.
If you want to load images / textures / resources, there's probably an stb / stb-style
library. Those are always really good.

If it's for general purpose file-loading / file-writing, it's probably worth just rolling your own code.

Hope it helps!

Edited by Matt on
For simple stuff stdio file handling works fine. Just avoid STL, iostream performance is terrible.
But once you want to do something more, it won't be enough. You'll need to use platform specific native file API. On Windows it is CreateFile & friends, on Linux/macOS it is open syscall. That will give you more control, for example, memory mapped files, reading/writing at offset without seeking, even async I/O. Consoles usually have their own API.
Big game engines typically have layers over layers over file API that wraps things in a way that it is easier to use in engine framework.

Edited by Mārtiņš Možeiko on
mmozeiko
on Linux/macOS it is open syscall. That will give you more control, for example, memory mapped files, reading/writing at offset without seeking, even async I/O. Consoles usually have their own API.


Just to be sure, how do you read/write without seeking on linux ? you use mmap ?

Edited by albatros on
albatros
mmozeiko
on Linux/macOS it is open syscall. That will give you more control, for example, memory mapped files, reading/writing at offset without seeking, even async I/O. Consoles usually have their own API.


Just to be sure, how do you read/write without seeking on linux ? you use mmap ?


you can use pread which adds a file offset to the parameter list