Error messages from file I/O should be read from OS (non-win32)

Bug #217878 reported by qwertitis
2
Affects Status Importance Assigned to Milestone
DC++
Fix Released
Undecided
Unassigned
LinuxDC++
Fix Released
Low
Razzloss

Bug Description

If there are errors while reading or otherwise working with files, make sure that the error messages are taken from the operating system, instead of just constant strings. This makes it much easier to detect full disks, etc. (No, the previous code won't do that, whatever it says.)

This is a patch originally made for Linux DC++, obviously, as the affected code is #ifndef on win32.

Tags: core
Revision history for this message
qwertitis (qwertitis-deactivatedaccount) wrote :
Revision history for this message
Steven Sheehy (steven-sheehy) wrote :

On POSIX strerror_r returns an int, and on GNU it returns a char*. This will cause trouble on different systems. I understand the need for a thread safe version of strerror, but it may not be worth it if causes compilation issues. It is doubtful different threads call strerror at the exact same time and even if they did it will only affect the error's output, not some core functionality of the program.

Also, allocating so much memory on the stack will cause some flavors of *nix to fail (particularly the BSD family). If we're going to keep strerror_r, char[] needs to be changed to a boost::scoped_array (AutoArray in old dcpp cores) so that it allocates on the heap and automatically deletes itself when it goes out of scope. Because of these two issues, I recommend we keep strerror.

In the write function, "int left" needs to be of type size_t and pointer should probably be void*. They will work as is, but we should probably use the types the system call requires.

Revision history for this message
Jacek Sieka (arnetheduck) wrote :

what steven says sounds all reasonable - steven, once this patch is up to your standards, feel free to commit (as well as any other nix-only parts)...

Revision history for this message
qwertitis (qwertitis-deactivatedaccount) wrote :

Thanks for the review. Removed the strerror_r changes. Fixed int left to ssize_t left.

I need the char* to be able to do the pointer arithmetics. I don't understand why I can't have char* implicitly cast into void*. Suggestions? Explicit cast?

Revision history for this message
Jacek Sieka (arnetheduck) wrote :

implicit to void* is fine by me - that's why void* exists after all...casting to char* is erm...ugly but necessary sometimes (and it works even in the face of strict aliasing)

Changed in dcplusplus:
status: New → Fix Committed
MikeJJ (mrmikejj)
Changed in dcplusplus:
status: Fix Committed → Fix Released
Changed in linuxdcpp:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
qwertitis (qwertitis-deactivatedaccount) wrote :

Finally... been patching this manually since I don't know when.

Changed in linuxdcpp:
assignee: nobody → individ
status: Confirmed → In Progress
Revision history for this message
Steven Sheehy (steven-sheehy) wrote :

Will be fixed once we merge 0707 into trunk.

Changed in linuxdcpp:
assignee: individ → razzloss
Changed in linuxdcpp:
status: In Progress → Fix Committed
Changed in linuxdcpp:
status: Fix Committed → Fix Released
Razzloss (razzloss)
Changed in linuxdcpp:
status: Fix Released → Fix Committed
Changed in linuxdcpp:
milestone: none → 1.1.0
tags: added: core
Changed in linuxdcpp:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.