After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 59703 - No way of error detection for g_get_current_dir()
No way of error detection for g_get_current_dir()
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: general
1.3.x
Other All
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2001-08-28 21:58 UTC by Timur Bakeyev
Modified: 2011-02-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Timur Bakeyev 2001-08-28 21:58:42 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.
Comment 1 Alexander Larsson 2001-09-08 01:36:16 UTC
Why is this an API bug. It should just return NULL on error.
Comment 2 Timur Bakeyev 2001-09-08 11:50:03 UTC
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...
Comment 3 Owen Taylor 2001-09-19 15:08:25 UTC
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
Comment 4 Timur Bakeyev 2001-09-19 15:15:45 UTC
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?
Comment 5 Owen Taylor 2001-09-19 15:30:10 UTC
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.