C print file path from FILE*

前端 未结 3 1730
生来不讨喜
生来不讨喜 2020-12-11 05:44
FILE * fd = fopen (\"/tmp/12345\",\"wb\");

If I have the variable fd , how can I print the file path ? (/tmp/12345) in Linux env.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 06:17

    There's no standard way to retrieve a pathname from a FILE * object, mainly because you can have streams that aren't associated with a named file (stdin, stdout, stderr, pipes, etc.). Individual platforms may supply utilities to retrieve a path from a stream, but you'd have to check the documentation for that platform.

    Otherwise, you're expected to keep track of that information manually.

提交回复
热议问题