X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fglkunix.c;h=bdadbafca72b48f9bfff88fcbb0d2d5c537217f7;hb=9ee259d9a29d83d79d912d1716b4044c63e90343;hp=13b44ec4fb91eb38b58bd55f287df7fa371826c1;hpb=43b334356e9e0003589d506ae74a8c85e5b9349d;p=projects%2Fchimara%2Fchimara.git
diff --git a/libchimara/glkunix.c b/libchimara/glkunix.c
index 13b44ec..bdadbaf 100644
--- a/libchimara/glkunix.c
+++ b/libchimara/glkunix.c
@@ -7,34 +7,67 @@
#include "fileref.h"
#include "stream.h"
-extern GPrivate *glk_data_key;
+extern GPrivate glk_data_key;
/**
- * glkunix_stream_open_pathname:
- * @pathname: A path to a file, in the system filename encoding.
- * @textmode: Bitfield with one or more of the fileusage_
constants.
+ * glkunix_stream_open_pathname_gen:
+ * @pathname: A path to a file, in the system filename encoding.
+ * @writemode: 0 for read-only mode, 1 for write mode.
+ * @textmode: 0 for binary mode, 1 for text mode.
* @rock: The new stream's rock value.
*
- * Opens an arbitrary file, in read-only mode. Note that this function is
+ * Opens an arbitrary file for reading or writing. (You cannot open a file for
+ * appending using this call.) Note that this function is
* only available during glkunix_startup_code(). It is
* inherently non-portable; it should not and cannot be called from inside
* glk_main().
+ *
+ * Returns: A new stream, or %NULL if the file operation failed.
+ */
+strid_t
+glkunix_stream_open_pathname_gen(char *pathname, glui32 writemode, glui32 textmode, glui32 rock)
+{
+ ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);
+
+ if(!glk_data->in_startup)
+ ILLEGAL("glkunix_stream_open_pathname_gen() may only be called from "
+ "glkunix_startup_code().");
+
+ g_return_val_if_fail(pathname, NULL);
+ g_return_val_if_fail(strlen(pathname) > 0, NULL);
+
+ frefid_t fileref = fileref_new(pathname, NULL, rock,
+ textmode? fileusage_TextMode : fileusage_BinaryMode,
+ writemode? filemode_Write : filemode_Read);
+ return file_stream_new(fileref, writemode? filemode_Write : filemode_Read, rock, FALSE);
+}
+
+/**
+ * glkunix_stream_open_pathname:
+ * @pathname: A path to a file, in the system filename encoding.
+ * @textmode: 0 for binary mode, 1 for text mode.
+ * @rock: The new stream's rock value.
+ *
+ * This opens a file for reading. It is a less-general form of
+ * glkunix_stream_open_pathname_gen(), preserved for backwards compatibility.
+ *
+ * This should be used only by glkunix_startup_code().
*
* Returns: A new stream, or %NULL if the file operation failed.
*/
strid_t
glkunix_stream_open_pathname(char *pathname, glui32 textmode, glui32 rock)
{
- ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
-
+ ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);
+
if(!glk_data->in_startup)
ILLEGAL("glkunix_stream_open_pathname() may only be called from "
"glkunix_startup_code().");
-
+
g_return_val_if_fail(pathname, NULL);
g_return_val_if_fail(strlen(pathname) > 0, NULL);
-
- frefid_t fileref = fileref_new(pathname, rock, usage, filemode_Read);
+
+ frefid_t fileref = fileref_new(pathname, NULL, rock, textmode? fileusage_TextMode : fileusage_BinaryMode, filemode_Read);
return file_stream_new(fileref, filemode_Read, rock, FALSE);
}
@@ -56,8 +89,8 @@ glkunix_set_base_file(char *filename)
g_return_if_fail(filename);
g_return_if_fail(strlen(filename) > 0);
- ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
-
+ ChimaraGlkPrivate *glk_data = g_private_get(&glk_data_key);
+
gchar *dirname = g_path_get_dirname(filename);
if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
{
@@ -157,4 +190,4 @@ parse_command_line(glkunix_argumentlist_t glkunix_arguments[], int argc, char *a
g_slist_free(arglist);
return TRUE;
-}
\ No newline at end of file
+}