GNOME Bugzilla – Bug 59703
No way of error detection for g_get_current_dir()
Last modified: 2011-02-18 15:47:37 UTC
Function g_get_current_dir() doesn't have any indication of an errorness conditions. In case when one of the underlaying functions failed to return a CWD, usually when one of the dirs in the path is not readable - the function returns G_DIR_SEPARATOR, which can't be distict from the case, when CWD is '/'. That's already affected MC, which tried to use this function and in general, I think, not a well defined API.
Why is this an API bug. It should just return NULL on error.
Alex, you are completely right - it should return some indication in case of error, preferably 0 or NULL. Return values of function in case of errors still a part of API - it just means API badly designed in this case, if it doesn't give programmer a way to know, that there is an error.. I think, that the fix is trivial, but it should happend BEFORE glib 2.0 freeze, and all the programms, that rely on this broken behaviour should be reviewed. If we leave this behaviour now, it'll become a part of API, and we never get rid of it.... I guess, glib2.0 should be examed agains such ill-behaved functions NOW. I'm afraid, that there are more of them than only this one...
We can't change this function; most users of this function would be _more_ broken if it suddenlty started returning NULL than currently. Nobody would know to test for NULL, so they would segfault. Yes, returning "/" when an error occurs is bad, I won't defend it, but basically when getcwd() is erroring things are going to be pretty screwed up anyways, and studying most code using g_get_current_dir(), it would be pretty difficult to do much better. I would advising writing your own utility function for mc
Owen, in general I agree with you, but with glib2.0 we are bringing quite a lot of incompatability with the glib 1.2 API, so why no to make the things "right" this time?
For glib, we have virtually no incompatibility with the 1.2 API, and in the places we have it (implementing your own main loop sources, mainly), it's obvious breakage caught by the caller, not a function that previously always returned something suddently returning NULL.