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 572466 - g_fopen and friends: should also state how to close a stream
g_fopen and friends: should also state how to close a stream
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: docs
unspecified
Other All
: Normal minor
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2009-02-19 18:04 UTC by Øystein Johansen
Modified: 2018-05-24 11:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
improve documentation for Win32 case (1020 bytes, patch)
2012-02-17 15:50 UTC, David King
needs-work Details | Review

Description Øystein Johansen 2009-02-19 18:04:18 UTC
Documentation 
Section: Reference doc for glib.
A wrapper for the stdio fopen() function. The fopen() function opens a file and associates a new stream with it.

Because file descriptors are specific to the C library on Windows, and a file descriptor is partof the FILE struct, the FILE pointer returned by this function makes sense only to functions in the same C library. Thus if the GLib-using code uses a different C library than GLib does, the FILE pointer returned by this function cannot be passed to C library functions like fprintf() or fread().

See your C library manual for more details about fopen().

filename : 	a pathname in the GLib file name encoding (UTF-8 on Windows)
mode : 	a string describing the mode in which the file should be opened
Returns : 	A FILE pointer if the file was successfully opened, or NULL if an error occurred

Since 2.6

Correct version:


Other information:
I suggest that the documentation also says how to close an open file. You actually have to google around and browse other source file to find that there is no g_close(). A coder may wonder: "Is it ok to close the file with close() when it's opened with g_fopen()?"
Comment 1 David King 2012-02-17 15:50:45 UTC
Created attachment 207860 [details] [review]
improve documentation for Win32 case

As there is no g_*() wrapper for close or fclose, it would appear to be impossible (given the current documentation) to close a file opened by g_fopen() under Windows, if the C library used by the application and the one used by GLib are different. The attached patch adds a note to hopefully make this clearer, and suggests to use convenience functions instead.
Comment 2 David King 2012-02-18 08:36:46 UTC
Comment on attachment 207860 [details] [review]
improve documentation for Win32 case

Dieter Verfaillie mentioned on IRC that:

it is possible to get a valid fd for msvcrt when you have an fd valid for msvcrX
it involves getting a handle by calling _get_osfhandle from msvcrX (which you can get at with the appropriate GetModuleHandle/GetProcAddress magic)
and then passing said handle to _open_osfhandle (in _O_RDONLY mode) from msvcrt
off course, leaking fd's becomes quite easy when using this technique...
Comment 3 Matthias Clasen 2013-02-05 04:30:04 UTC
Note that we recently added g_close wrapper, so the documentation may need to be revisited now.
Comment 4 GNOME Infrastructure Team 2018-05-24 11:45:38 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/198.