9

Looking at the man page for fopen I cannot get a definite answer to this question.

FILE *fopen(const char *path, const char *mode);

I understand that fopen returns a file pointer to a stream but is a file descriptor created as a byproduct? I am trying to make sure that I include the flag FD_CLOEXEC on every instance a file descriptor is created. If a file descriptor is in fact created from fopen what is the best way to use fnctl() when there is no "fd" to use as input.

Thanks.

Eric Dand
  • 1,106
  • 13
  • 37
Jon Kump
  • 574
  • 7
  • 19

1 Answers1

17

On Unix (which I assume you're using because you're mentioning fcntl) it does open a file descriptor, as fopen(3) eventually calls open(2). You can get that file descriptor via fileno(3).

cnicutar
  • 178,505
  • 25
  • 365
  • 392