% File system hooks

## API: ALLEGRO_FS_ENTRY

Opaque filesystem entry object.
Represents a file or a directory (check with [al_is_directory]
or [al_is_file]).
There are no user accessible member variables.

# Enumerations

## API: ALLEGRO_FS_FILTER

File system search filters.

Type Filters:

* ALLEGRO_FS_FILTER_DRIVES - Include Drive letters
* ALLEGRO_FS_FILTER_DIRS - Include Directories
* ALLEGRO_FS_FILTER_FILES - Include Files
* ALLEGRO_FS_FILTER_NOSYMLINKS - Exclude symlinks
* ALLEGRO_FS_FILTER_ALLENTRIES - Include all entries (including symlinks)

Permission Filters:

* ALLEGRO_FS_FILTER_READABLE - Entry is Readable
* ALLEGRO_FS_FILTER_WRITABLE - Entry is Writeable
* ALLEGRO_FS_FILTER_EXECUTABLE - Entry is Executable

Access Filters:

* ALLEGRO_FS_FILTER_HIDDEN - Entry is hidden
* ALLEGRO_FS_FILTER_SYSTEM - Entry is marked as a system file

Other Filters:

* ALLEGRO_FS_FILTER_ALLDIRS - Include all directories, including '.' and '..'
* ALLEGRO_FS_FILTER_CASESENSITIVE - Search case sentitively
* ALLEGRO_FS_FILTER_NODOTDOT - Exclude '..'
* ALLEGRO_FS_FILTER_NOFILTER - No filtering

## API: ALLEGRO_FS_MKTEMP_UNLINK

al_fs_mktemp unlink modes

* ALLEGRO_FS_MKTEMP_UNLINK_NEVER - Don't auto unlink
* ALLEGRO_FS_MKTEMP_UNLINK_NOW - Unlink on open, makes file "hidden"
* ALLEGRO_FS_MKTEMP_UNLINK_ON_CLOSE - Unlink on close

## API: ALLEGRO_FS_MODE

Filesystem modes/types

* AL_FM_READ - Readable
* AL_FM_WRITE - Writable
* AL_FM_EXECUTE - Executable
* AL_FM_HIDDEN - Hidden
* AL_FM_ISFILE - Regular file
* AL_FM_ISDIR - Directory

## API: ALLEGRO_FS_SORT

Filesystem search sort flags

* ALLEGRO_FS_SORT_NAME - By name
* ALLEGRO_FS_SORT_TIME - By time
* ALLEGRO_FS_SORT_SIZE - By size
* ALLEGRO_FS_SORT_UNSORTED - Don't sort

* ALLEGRO_FS_SORT_DIRSFIRST - Directories first
* ALLEGRO_FS_SORT_REVERSED - Reverse sort
* ALLEGRO_FS_SORT_CASESENSITIVE - Case Sensitive
* ALLEGRO_FS_SORT_DIRSLAST - Directories Last
* ALLEGRO_FS_SORT_TYPE - By Type (extension?)

XXX do we need ALLEGRO_FS_SORT_TYPE?  It sounds like we don't even
know what it should do.

## API: ALLEGRO_SEEK

* ALLEGRO_SEEK_SET - Seek to pos from beginning of file
* ALLEGRO_SEEK_CUR - Seek to pos from curent position
* ALLEGRO_SEEK_END - Seek to pos from end of file

# Search Path Routines

## API: al_add_search_path

Adds a path to the list of directories to search for files when
searching/opening files with a relative pathname.

## API: al_get_search_path

Fills in 'dest' up to 'len' bytes with the 'idx'th search path item.

Parameters:
idx - index of search path element requested
dest - memory buffer to copy path to
len - length of memory buffer

Returns true on success, and false on failure.

errno is set to indicate the error.

Possible Errors:
* EINVAL - invalid item selected
* ERANGE - buffer not large enough

See also: [al_get_errno]

## API: al_search_path_count

Returns the number of items in the search path list.

# File Manipulation

## API: al_create_entry

Creates an [ALLEGRO_FS_ENTRY] object pointing to path.
'path' can be a file or a directory and must not be NULL.

## API: al_destroy_entry

Destroys a fs entry handle.
Closes file if it was open.

## API: al_close_entry

Closes fs entry.

## API: al_closedir

Closes a previously opened directory entry object.

[al_close_entry] is also a valid way to close any entry object.

Does not free the entry object if it was opened with [al_opendir].
XXX This is probably a bug.

Returns true on succes, false on failure and fills in errno to indicate the error.

## API: al_mkdir

Creates a new directory on disk given the path 'path'.

Returns false on error and fills in errno to indicate the error.

See also: [al_get_errno]

## API: al_mktemp

Make a temporary randomly named file given a filename 'template' and 'ulink'
flags.

'template' is a string giving the format of the generated filename and
should include one or more capital Xs.  The Xs are replaced with random
alphanumeric chars.

'ulink' is one of:

* ALLEGRO_FS_MKTEMP_UNLINK_NOW - unlink now to create an anonymous temporary file
* ALLEGRO_FS_MKTEMP_UNLINK_ON_CLOSE - unlink when entry is closed
* ALLEGRO_FS_MKTEMP_UNLINK_NEVER - don't unlink

## API: al_open_entry

Opens handle with mode 'mode'.
mode is a stdio type mode, ie: "r", "w", etc

Returns true on success, false on failure and fills in errno to indicate the error.

See also: [al_get_errno]

## API: al_opendir

Creates and opens a filesystem entry object for a directory.

Returns NULL on error.

## API: al_readdir

Reads the next dir item name into 'name' buffer, up to 'size' chars.

Warning: this may leave the filename truncated.
XXX and how do users know if that's the case?

Returns non zero on error.

## API: al_unlink_entry

"Unlink" or delete this file on disk.

Returns true on success, and false on failure, error is indicated in errno.

## API: al_unlink_str

Unlink 'path' entry from disk.

Returns true on success, and false on failure.

errno is filled in to indicate the error.

See Also:
[al_unlink_entry]

## API: al_fstat

Updates stat info for entry 'fp'.

Returns true on success, false on failure.
Fills in errno to indicate the error.

See also [al_get_errno] [al_get_entry_atime] [al_get_entry_ctime] [al_is_directory]
[al_is_file] [al_get_entry_mode]

# File Properties

## API: al_is_present

Check if the given entry exists on disk.
Returns true if it does exist or false if it doesn't exist, or an error occured.
Error is indicated in errno.

## API: al_is_present_str

Check if entry 'path' exists on disk.

See Also:
[al_is_present]

## API: al_is_file

Return true iff this entry is a regular file.

## API: al_is_file_str

Return true if 'path' is a file.

See Also:
[al_is_file]

## API: al_is_directory

Return true iff this entry is a directory.

## API: al_is_directory_str

Return true if 'path' is a directory.

See Also:
[al_is_directory]

## API: al_get_entry_mode

Returns the entry's mode flags.

See also: [al_get_errno]

See the [ALLEGRO_FS_MODE] enum for valid flags.

## API: al_get_entry_mode_str

Returns stat 'mode' for fs entry 'path'.

See Also:
[ALLEGRO_FS_MODE]

## API: al_get_entry_atime

Returns the time in seonds since the epoch since the entry was last
accessed.

Warning: some filesystem either don't support this flag, or people turn it
off to increase performance.
It may not be valid in all circumstances.

## API: al_get_entry_atime_str

Returns last access time for fs entry 'path'.

See Also:
[al_get_entry_atime]

## API: al_get_entry_ctime

Returns the time in seconds since the epoch this entry was created on the
filsystem.

## API: al_get_entry_ctime_str

Returns creation time for fs entry 'path'.

See Also:
[al_get_entry_ctime]

## API: al_get_entry_mtime

Returns the time in seconds since the epoch since the entry was last
modified.

## API: al_get_entry_mtime_str

Returns last modification time for fs entry 'path'.

See Also:
[al_get_entry_mtime]

## API: al_get_entry_name

Fills in buf up to size bytes including trailing NULL char with the entry's name

Returns true on success, and false on error.

errno is set to indicate the error.

If buf isn't large enough, errno will be set to ERANGE

## API: al_get_entry_size

Returns the size, in bytes, of the given entry.

## API: al_get_entry_size_str

Returns file size for fs entry 'path'.

See Also:
[al_get_entry_size]

# File I/O

## API: al_fopen

Creates and opens an ALLEGRO_FS_ENTRY object given path and mode.

'path' - the path to open

'mode' - mode to open the entry in ("r", "w", etc.)

## API: al_fclose

Closes the given file entry object.
Will destroy the handle if it was opened with al_fopen.

If you do not wish the entry object destroyed, use [al_close_entry] instead.

## API: al_feof

Returns true if we have an end of file condition.

## API: al_ferror

Returns true if there was some sort of previous error.

## API: al_fgets

Reads a string of bytes terminated with a newline (\\r,\\n,\\r\\n).

Parameters:

* p - buffer to fill
* max - maximum size of buffer
* f - entry to read from

Returns:
p

## API: al_fputs

Writes a string to file.

Parameters:

* p - string to write
* f - file handle to write to

Returns:
0 on success or -1 on error

Note:
Function converts string to UTF8 before writing.

## API: al_fflush

Flush any pending writes to 'fp' to disk.

Returns true on success, false otherwise, and errno is set to indicate the error.

See also: [al_get_errno]

## API: al_fgetc

Read and return next byte in entry 'f'.
Returns EOF on end of file, and 0 on other errors
(XXX this is probably a bug)

## API: al_fputc

Write a single byte to entry.

Parameters:
c - byte value to write
f - entry to write to

Returns:
EOF on error

## API: al_fungetc

Ungets a single byte from a file. Does not write to file, it only places the
char back into the entry's buffer.

See also [al_get_errno]

## API: al_fread32le

Reads a 32-bit word in little-endian format (LSB first).

Returns:
The read 32-bit word or EOF on error.

## API: al_fwrite32le

Writes a 32-bit word in little-endian format (LSB first).

Returns:
The written 32-bit word or EOF on error.

## API: al_fread16le

Reads a 16-bit word in little-endian format (LSB first).

Returns:
The read 16-bit word or EOF on error

## API: al_fwrite16le

Writes a 16-bit word in little-endian format (LSB first).

Returns:
The written 16-bit word or EOF on error.

## API: al_fread32be

Read a 32-bit word in big-endian format (MSB first).

Returns:
The read 32-bit word or EOF on error

## API: al_fwrite32be

Writes a 32-bit word in big-endian format (MSB first).

Returns:
The written 32-bit word or EOF on error.

## API: al_fread16be

Reads a 16-bit word in big-endian format (MSB first).

Returns:
The read 16-bit word or EOF on error.

## API: al_fwrite16be

Writes a 16-bit word in big-endian format (MSB first).

Returns:
The written 16-bit word or EOF on error

## API: al_fread

Read 'size' bytes into 'ptr' from entry 'fp'

Return number of bytes actually read.

## API: al_fwrite

Write 'size' bytes from 'ptr' into file 'fp'

Return number of bytes actually written or 0 on error.

Does not distinguish between EOF and other errors.
Use [al_feof] and [al_ferror]
to tell them apart.

## API: al_fseek

Seek to 'offset' in file based on 'whence'.

'whence' can be:

* ALLEGRO_SEEK_SET - Seek from beggining of file
* ALLEGRO_SEEK_CUR - Seek from current position
* ALLEGRO_SEEK_END - Seek from end of file

Returns true on success, false on failure and errno is set to indicate the error.

On some platforms this function may not support large files.

See also: [al_get_errno]

## API: al_ftell

Returns the current position in file, or -1 on error.
errno is set to indicate the error.

On some platforms this function may not support large files.

See also: [al_get_errno]

# Other

## API: al_getcwd

Fill in 'buf' up to 'len' characters with the current working directory.

Returns true on success, false on failure.

errno is filled in to indicate the error.

Possible Errors:
* ERANGE - buffer is not large enough

See also: [al_get_errno]

## API: al_chdir

Changes the current working directory to 'path'.

Returns -1 on error.

## API: al_path_to_sys

Converts path 'orig' to system dependant format.
XXX return code?

## API: al_path_to_uni

Converts path 'orig' to 'allegro' format.
XXX return code?

## API: al_path_sep

Fills in 'sep' up to 'len' characters with the path separator string.
XXX return code?

## API: al_drive_sep

Fills in 'sep' up to 'len' characters with the drive separator string.
XXX return code?


