The readd(), readu(), and readhu() functions are all used to read
various forms of integers. The readl() and readw() are for reading
either lines or individual whitespace-delimited words
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I rename cache_file_write() to file_write(), and implement the
corresponding file_read() for binary data.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I also take this opportunity to add a OPEN_WRITE_BINARY mode to support
writing binary data to files.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This function currently only supports opening files for reading, but it
will soon be expanded to supporting writes as well. To support binary
reads, I add a new OPEN_READ_BINARY open mode.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I'll eventually want to support text and binary files in both locations,
so cache files might need access to this too.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This change means removing cache files is now supported. As a bonus,
we try to remove empty subdirectories to keep down the clutter.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This might also be useful for cache files to track their current state.
To help with accurate tracking, I take this opportunity to add a CLOSED
state that files default to.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I also introduce a "file_operations" struct that will be used in the
future to do slightly different things for cache and data files.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
And rework the init functions at the same time to reflect that data
files can now be placed under a subdirectory.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I'm going to create a unified struct file that should be able to share
code between data and cache files. The first step is to push the old
structure to the side so it can still be used in other places.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This makes file versioning way easier, since every file will have the
same version. I'll still need to manage minimum-supported versions, but
that shouldn't be too difficult going forward.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I'm hitting this problem while developing 6.5, since file formats are
going to change. Let's handle this situation gracefully rather than
segfaulting.
This patch changes versioning problems into fatal errors to prevent us
from overwriting data already on disk.
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
I don't think it makes sense that callers of file_open() are expected to
check the file version after opening. This should be something handled
by the file code so we can print a consistent error message.
Implements issue #5: Better file versioning
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
I want to be able to print any message as an error message without
relying on errno. Let's handle this by introducing REPORT_ERRNO() to
look up the right error message for a given errno.
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
And then rename the temporary file when closed. This protects users
data in case Ocarina gets killed.
Implements issue #31: Make file writes seem atomic
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
There are enough differences in the read and write paths that
__file_open_common() was still trying to account for. Let's make a
simpler wrapper around g_fopen() and move differing code into
__file_open_read() and __file_open_write().
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
I'm only setting this to a static string, so it doesn't make sense to
store this as a char array. Let's use a string pointer instead.
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
I'm going to use this for saving album art to the right place. I moved
it into an include file to avoid duplicating code.
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>