/* Add it to the global stream list */
glk_data->stream_list = g_list_prepend(glk_data->stream_list, str);
str->stream_list = glk_data->stream_list;
-
+
return str;
}
-/* Internal function: Stuff to do upon closing any type of stream. */
+/* Internal function: Stuff to do upon closing any type of stream. Call only
+ from Glk thread. */
void
stream_close_common(strid_t str, stream_result_t *result)
{
ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
-
- /* Remove the stream from the global stream list */
- glk_data->stream_list = g_list_delete_link(glk_data->stream_list, str->stream_list);
-
- /* If it was the current output stream, set that to NULL */
- if(glk_data->current_stream == str)
- glk_data->current_stream = NULL;
-
- /* If it was one or more windows' echo streams, set those to NULL */
- winid_t win;
- for(win = glk_window_iterate(NULL, NULL); win;
- win = glk_window_iterate(win, NULL))
- if(win->echo_stream == str)
- win->echo_stream = NULL;
if(glk_data->unregister_obj)
{
str->disprock.ptr = NULL;
}
+ /* If the stream was one or more windows' echo streams, set those to NULL */
+ winid_t win;
+ for(win = glk_window_iterate(NULL, NULL); win;
+ win = glk_window_iterate(win, NULL))
+ if(win->echo_stream == str)
+ win->echo_stream = NULL;
+
/* Return the character counts */
if(result)
{
result->readcount = str->read_count;
result->writecount = str->write_count;
}
+
+ /* Remove the stream from the global stream list */
+ glk_data->stream_list = g_list_delete_link(glk_data->stream_list, str->stream_list);
+
+ /* If it was the current output stream, set that to NULL */
+ if(glk_data->current_stream == str)
+ glk_data->current_stream = NULL;
str->magic = MAGIC_FREE;
g_free(str);
* @str: A stream.
*
* Retrieves the stream @str's rock value. See <link
- * linkend="chimara-Rocks">Rocks</link>.
+ * linkend="chimara-Rocks">Rocks</link>. Window streams always have rock 0; all
+ * other streams return whatever rock you created them with.
*
* Returns: A rock value.
*/
* equivalent to
* |[
* for (ptr = s; *ptr; ptr++)
- * #glk_put_char(*ptr);
+ * glk_put_char(*ptr);
* ]|
* However, it may be more efficient.
*/
* to:
* |[
* for (i = 0; i < len; i++)
- * #glk_put_char(buf[i]);
+ * glk_put_char(buf[i]);
* ]|
* However, it may be more efficient.
*/
* Opens a stream which reads to or writes from a disk file. If @fmode is
* %filemode_Read, the file must already exist; for the other modes, an empty
* file is created if none exists. If @fmode is %filemode_Write, and the file
- * already exists, it is truncated down to zero length (an empty file). If
- * @fmode is %filemode_WriteAppend, the file mark is set to the end of the
- * file.
+ * already exists, it is truncated down to zero length (an empty file); the
+ * other modes do not truncate. If @fmode is %filemode_WriteAppend, the file
+ * mark is set to the end of the file.
+ *
+ * <note><para>
+ * Note, again, that this doesn't match stdio's fopen() call very well. See
+ * <link linkend="filemode-WriteAppend">the file mode constants</link>.
+ * </para></note>
+ *
+ * If the filemode requires the file to exist, but the file does not exist,
+ * glk_stream_open_file() returns %NULL.
+ *
+ * The file may be read or written in text or binary mode; this is determined
+ * by the @fileref argument. Similarly, platform-dependent attributes such as
+ * file type are determined by @fileref. See <link
+ * linkend="chimara-File-References">File References</link>.
*
* When writing in binary mode, Unicode values (characters greater than 255)
* cannot be written to the file. If you try, they will be stored as 0x3F