When I execute fopen_s(&fid, FILE_NAME, "r")
, fid
is null and errno
is 17.
How is this even possible that when I try to open a file for reading I get EEXIST
error?
Asked
Active
Viewed 1,384 times
1

Deduplicator
- 44,692
- 7
- 66
- 118

fudge
- 276
- 5
- 14
-
Sometimes, it has to do with an invalid path. Specifically, if a directory is specified in FILE_NAME, and that directory does not exist... It would be helpful if more detail were supplied so that the context of the call could be examined. – Mahonri Moriancumer Jul 15 '14 at 14:44
-
When I change the directory name of the file name I get the error: "No such file or directory" – fudge Jul 15 '14 at 14:55
-
Do you know the file you are trying to open exists? Do you know if the program you are running has permission to read the directory and file? – jxh Jul 15 '14 at 14:56
-
Yes, it exists. And yes I have permissions. No permission is a different error. EEXIST is "File exist" error which should only happen if the open operation doesn't make sense if the file doesn't exist. – fudge Jul 15 '14 at 15:01
-
I tried using ifstream and it works. wt*?? – fudge Jul 15 '14 at 15:11
1 Answers
3
errno
is not meaningful after a call to fopen_s
. The error code is in the return value of the function.
Source: C11 Annex K, K.3.5.2.2 The freopen_s function, paragraph 9:
The fopen_s function returns zero if it opened the file. If it did not open the file or if there was a runtime-constraint violation, fopen_s returns a nonzero value.

R.. GitHub STOP HELPING ICE
- 208,859
- 35
- 376
- 711