Files

Cahute supports interacting with the local filesystem to read and export files. This abstraction allows command-line utilities to be portable, as well as support all file formats surrounding CASIO calculators, documented in File formats.

All files are represented by the cahute_file type. They are opened and used differently depending on the situations, but must always be closed after usage using cahute_close_file(). They always exist within a context; see Contexts for more information.

Note

A file is considered to be handled by Cahute exclusively. When reading, the size is computed once on opening the file, then considered to stay the same during the file handle lifetime.

File reading

For reading a file using Cahute, one must first open the file using cahute_open_file(). If this function succeeds, many operations can then be used, as described in the following subsections.

Manual file reading

One can read raw data from the file by using the following functions:

Note

cahute_get_file_size() and cahute_read_from_file() use unsigned long to represent file sizes and offset.

The value is guaranteed to fit, since if the file was too large for the size to fit in an unsigned long, cahute_open_file() would have failed with CAHUTE_ERROR_SIZE.

Type guessing

One can use cahute_guess_file_type() to determine the file type, as one of the CAHUTE_FILE_TYPE_* macros.

Main memory data reading

One can use cahute_get_data_from_file() to extract main memory data from the file, as described in Main memory data.

Raw file creation

For creating a raw file using Cahute, one must first create and open the file using cahute_create_file(), while specifying the path and size of the file to create.

Warning

For performance and compatibility reasons, the resulting file contents is not guaranteed to contain anything particular. If this method is used to create an all-zeroes file, the contents of the file must be manually set.

From here, the following functions can be used:

Note

For command-line utilities that support writing the output directly to standard output, cahute_open_stdout() can also be used to create a file handle. There are however two limitations this brings:

  • cahute_get_file_size() will not be available anymore;

  • Only increasing offsets will be accepted with such a file handle, and skipping bytes will mean the skipped bytes will be emitted as zeroes.