This site is no longer active and is available for archival purposes only. Registration and login is disabled.

fopen error codes on failure


fopen error codes on failure

Postby Dan East » Aug 18, 2005 @ 1:48am

I try to use the fopen API for file IO as much as possible for portability. Typically if a file can't be opened I don't need to know why. However in some cases, for example when multiple programs read and write to the same file, I need to know if the file is simply locked for reading or writing, as opposed to it failing for some other reason (like the path is invalid, or the drive is full, etc).

With CreateFile and GetLastError I can determine exactly why I couldn't open the file.

Is there such a method with fopen? Or do I have to use a non-portable API to get that extra info?

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby Andy » Aug 18, 2005 @ 4:09am

strerror(errno)

According to KR: will give "an implementation defined error message corresponding to the integer in errno".
Andy
<font color=red size=3>Troll++</font>
 
Posts: 1288
Joined: Nov 1, 2003 @ 7:36am


Postby Dan East » Aug 18, 2005 @ 4:32am

Yeah, it looks like errno==EACCES will do it.

If not, I can always do a FindFirstFile to see if the file exists, and make sure it isn't a directory. If it meets that criteria but fopen can't open it then I can assume it is locked.

Thanks!

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum