Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about C fopen function

Tags:

c

While I was reading the reference about fopen function, I found out that FOPEN_MAX is a value that the "minimum number of streams that the implementation guarantees can be open simultaneously".

Why it is the minimum number of streams? Doesn't it have to be "the maximum number of streams...." ?

like image 849
Jaebum Avatar asked Sep 24 '26 07:09

Jaebum


2 Answers

Minimum number of streams that can be opened = guarantee that at least so many can be opened

Maximum number of streams that can be opened = guarantee that opening any more will certainly fail

What the wording means that if you have less than FOPEN_MAX streams open, it is guaranteed that at least one more can be opened, and the system does not necessarily provide any hard maximum

like image 196
Antti Huima Avatar answered Sep 26 '26 02:09

Antti Huima


It sounds counterintuitive that something "MAX" is the minimum number that can be opened simultaneously. But if you're writing portable code, that number is the effective maximum that you can use safely.

Consider this code:

if (num_open >= FOPEN_MIN) {
    // close some old ones
}

Looks odd, right? So calling it FOPEN_MAX makes sense.

like image 30
Dominic Cooney Avatar answered Sep 26 '26 01:09

Dominic Cooney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!