Jaebum
Jaebum

Reputation: 1570

Question about C fopen function

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...." ?

Upvotes: 2

Views: 589

Answers (4)

Dominic Cooney
Dominic Cooney

Reputation: 6545

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.

Upvotes: 3

President James K. Polk
President James K. Polk

Reputation: 42018

Poor wording in my opinion. It would be better to just say that the implementation guarantees that at least FOPEN_MAX streams may be open simultaneously. Note that if you try to open more streams, you may succeed, but it is not guaranteed in advance.

Upvotes: 1

Eld
Eld

Reputation: 984

on linux you can adjust the maximum number of allowed open file handles.
See the command ulimit for more information:

For example on my box running as my user right now any process would have a max number of 256 file handles opened at any given time.

$ ulimit -n
256

see the man page for ulimit for more information( here is a web version): http://ss64.com/bash/ulimit.html

However, I imagine you can't lower it below FOPEN_MAX

Upvotes: 0

Antti Huima
Antti Huima

Reputation: 25542

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

Upvotes: 10

Related Questions