NAME

src/io/filehandle.c - FileHandle utility functions

DESCRIPTION

This file defines a set of utility functions for the FileHandle PMC used by all operating systems. For the primary public I/O API, see src/io/api.c.

Functions

INTVAL Parrot_io_parse_open_flags
Parses a Parrot string for file open mode flags (r for read, w for write, a for append, and p for pipe) and returns the combined generic bit flags.
STRING *Parrot_io_make_string
Creates a STRING* suitable for returning results from IO read functions. The passed in buf parameter can:
  1. Point to a NULL STRING
  2. Point to a real STRING
  3. Point to a fake STRING with (strstart, bufused) holding the *buffer information.
In the third case, the buffer or STRING must be able to hold the required amount of data. For cases 1 and 2, a NULL strstart tells this function to allocate the STRING memory.
void Parrot_io_set_os_handle
Sets the os_handle attribute of the FileHandle object, which stores the low-level filehandle for the OS.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.Possibly, this function should reset some characteristics of the object (like buffer and file positions) to their default values.
PIOHANDLE Parrot_io_get_os_handle
Retrieve the os_handle attribute of the FileHandle object, which stores the low-level filehandle for the OS.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_flags
Set the flags attribute of the FileHandle object, which stores bitwise flags marking filehandle characteristics.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
INTVAL Parrot_io_get_flags
Set the flags attribute of the FileHandle object, which stores bitwise flags marking filehandle characteristics.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_file_size
Set the file_size attribute of the FileHandle object, which stores the current file size.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
PIOOFF_T Parrot_io_get_file_size
Get the file_size attribute of the FileHandle object, which stores the current file size.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_buffer_start
Set the buffer_start attribute of the FileHandle object, which stores the position of the start of the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
unsigned char *Parrot_io_get_buffer_start
Get the buffer_start attribute of the FileHandle object, which stores the position of the start of the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
unsigned char *Parrot_io_get_buffer_next
Get the buffer_next attribute of the FileHandle object, which stores the current position within the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_buffer_next
Set the buffer_next attribute of the FileHandle object, which stores the current position within the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
unsigned char *Parrot_io_get_buffer_end
Get the buffer_end attribute of the FileHandle object, which stores the position of the end of the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_buffer_end
Set the buffer_end attribute of the FileHandle object, which stores the position of the end of the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
INTVAL Parrot_io_get_buffer_flags
Get the buffer_flags attribute of the FileHandle object, which stores a collection of flags specific to the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_buffer_flags
Set the buffer_flags attribute of the FileHandle object, which stores a collection of flags specific to the buffer.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
size_t Parrot_io_get_buffer_size
Get the buffer_size attribute of the FileHandle object, which stores the size of the buffer (in bytes).Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_buffer_size
Set the buffer_size attribute of the FileHandle object, which stores the size of the buffer (in bytes).Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_clear_buffer
Clear the filehandle buffer and free the associated memory.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
PIOOFF_T Parrot_io_get_file_position
Get the file_pos attribute of the FileHandle object, which stores the current file position of the filehandle.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
PIOOFF_T Parrot_io_get_last_file_position
Get the file_pos attribute of the FileHandle object, which stores the current file position of the filehandle.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
void Parrot_io_set_file_position
Get the file_pos attribute of the FileHandle object, which stores the current file position of the filehandle. Also set the last_pos attribute to the previous value of file_pos.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
INTVAL Parrot_io_is_encoding
Check whether the encoding attribute of the filehandle matches a passed in string.Currently, this pokes directly into the C struct of the FileHandle PMC. This needs to change to a general interface that can be used by all subclasses and polymorphic equivalents of FileHandle. For now, hiding it behind a function, so it can be cleanly changed later.
INTVAL Parrot_io_close_filehandle
Flushes and closes the FileHandle PMC *pmc, but leaves the object intact to be reused or collected.
INTVAL Parrot_io_is_closed_filehandle
Test whether a filehandle is closed.
void Parrot_io_flush_filehandle
Flushes the FileHandle PMC *pmc.

SEE ALSO

src/io/unix.c, src/io/win32.c, src/io/stdio.c, src/io/io_private.h.