Unix Extensions

Unix Extensions — Unix-specific functions

Functions

Includes

#include <libchimara/glk.h>
#include <libchimara/glkstart.h>

Description

This section describes an extension to Glk for various Unix functions. It was written by Andrew Plotkin for the Glk libraries CheapGlk and GlkTerm.

You can put other startup code in glkunix_startup_code(). This should generally be limited to finding and opening data files. There are a few Unix Glk library functions which are convenient for this purpose.

Functions

glkunix_stream_open_pathname_gen ()

strid_t
glkunix_stream_open_pathname_gen (char *pathname,
                                  glui32 writemode,
                                  glui32 textmode,
                                  glui32 rock);

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().

Parameters

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.

 

Returns

A new stream, or NULL if the file operation failed.


glkunix_stream_open_pathname ()

strid_t
glkunix_stream_open_pathname (char *pathname,
                              glui32 textmode,
                              glui32 rock);

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().

Parameters

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.

 

Returns

A new stream, or NULL if the file operation failed.


glkunix_set_base_file ()

void
glkunix_set_base_file (char *filename);

Sets the library's idea of the “current directory” for the executing program. The argument should be the name of a file (not a directory). When this is set, glk_fileref_create_by_name() will create files in the same directory as that file, and glk_fileref_create_by_prompt() will base default filenames off of the file. If this is not called, the library works in the Unix current working directory, and picks reasonable default defaults.

Parameters

filename

A path to a file, in the system filename encoding.