Update Dispatch layer
[projects/chimara/chimara.git] / libchimara / stream.c
index b9d56cd03d4c055444a4198bfdfa067f7b3de7cd..f9a6cf5bf4cea649c405ff7382dc8a5767276707 100644 (file)
@@ -284,6 +284,7 @@ glk_stream_open_memory(char *buf, glui32 buflen, glui32 fmode, glui32 rock)
        str->file_mode = fmode;
        str->type = STREAM_TYPE_MEMORY;
        str->mark = 0;
+       str->endmark = 0;
        str->unicode = FALSE;
 
        if(buf && buflen) 
@@ -322,6 +323,7 @@ glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, glui32 fmode, glui32 rock
        str->file_mode = fmode;
        str->type = STREAM_TYPE_MEMORY;
        str->mark = 0;
+       str->endmark = 0;
        str->unicode = TRUE;
 
        if(buf && buflen) 
@@ -342,7 +344,7 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode)
 {
        VALID_FILEREF(fileref, return NULL);
        
-       gchar *modestr;
+       const gchar *modestr;
        /* Binary mode is 0x000, text mode 0x100 */
        gboolean binary = !(fileref->usage & fileusage_TextMode);
        switch(fmode) 
@@ -352,10 +354,10 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode)
                                ILLEGAL_PARAM("Tried to open a nonexistent file, '%s', in read mode", fileref->filename);
                                return NULL;
                        }
-                       modestr = g_strdup(binary? "rb" : "r");
+                       modestr = binary? "rb" : "r";
                        break;
                case filemode_Write:
-                       modestr = g_strdup(binary? "wb" : "w");
+                       modestr = binary? "wb" : "w";
                        break;
                case filemode_WriteAppend:
                case filemode_ReadWrite:
@@ -367,7 +369,7 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode)
                                IO_WARNING( "Error opening file", fileref->filename, g_strerror(errno) );
                                return NULL;
                        }
-                       modestr = g_strdup(binary? "r+b" : "r+");
+                       modestr = binary? "r+b" : "r+";
                }
                        break;
                default:
@@ -376,7 +378,6 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode)
        }
        
        FILE *fp = g_fopen(fileref->filename, modestr);
-       g_free(modestr);
        if(fp == NULL) {
                IO_WARNING( "Error opening file", fileref->filename, g_strerror(errno) );
                return NULL;
@@ -487,6 +488,64 @@ glk_stream_open_file_uni(frefid_t fileref, glui32 fmode, glui32 rock)
        return file_stream_new(fileref, fmode, rock, TRUE);
 }
 
+/**
+ * glk_stream_open_resource:
+ * @filenum: Resource chunk number to open.
+ * @rock: The new stream's rock value.
+ *
+ * Open the given data resource for reading (only), as a normal stream.
+ *
+ * <note><para>
+ *   Note that there is no notion of file usage &mdash; the resource does not
+ *   have to be specified as <quote>saved game</quote> or whatever.
+ * </para></note>
+ *
+ * If no resource chunk of the given number exists, the open function returns
+ * %NULL.
+ *
+ * As with file streams, a binary resource stream reads the resource as bytes. A
+ * text resource stream reads characters encoded as Latin-1.
+ *
+ * When reading from a resource stream, newlines are not remapped, even if they
+ * normally would be when reading from a text file on the host OS. If you read a
+ * line (glk_get_line_stream() or glk_get_line_stream_uni()), a Unix newline
+ * (0x0A) terminates the line.
+ *
+ * Returns: the new stream, or %NULL.
+ */
+strid_t
+glk_stream_open_resource(glui32 filenum, glui32 rock)
+{
+       g_warning("Not implemented");
+       return NULL;
+}
+
+/**
+ * glk_stream_open_resource_uni:
+ * @filenum: Resource chunk number to open.
+ * @rock: The new stream's rock value.
+ *
+ * Open the given data resource for reading (only), as a Unicode stream. See
+ * glk_stream_open_resource() for more information.
+ *
+ * As with file streams, a binary resource stream reads the resource as
+ * four-byte (big-endian) words. A text resource stream reads characters encoded
+ * as UTF-8.
+ *
+ * <note><para>
+ *   Thus, the difference between text and binary resources is only important
+ *   when opened as a Unicode stream.
+ * </para></note>
+ *
+ * Returns: the new stream, or %NULL.
+ */
+strid_t
+glk_stream_open_resource_uni(glui32 filenum, glui32 rock)
+{
+       g_warning("Not implemented");
+       return NULL;
+}
+
 /**
  * glk_stream_close:
  * @str: Stream to close.