fopen does not return

后端 未结 4 897
感情败类
感情败类 2021-02-15 02:49

I used \'fopen\' in a C program to open a file in readonly mode (r). But in my case I observed that fopen call does not return. It does not return NULL or valid pointer - execut

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 03:10

    Here's a few reasons:

    • You've corrupted memory somewhere, and all bets are off as to what's happening (run your program through valgrind)
    • You're calling this code inside a signal handler, fopen() is not signal async safe, so really anything could happen (a deadlock due to the FILE* internal mutex is common though)
    • The file is a fifo , in which cases opening the file will block until someone opens the file at the other end(read/writing)
    • The file is on a stale NFS mount.
    • The file is a character/block special file with semantics that open blocks until something interesting happens,

提交回复
热议问题