|
|
File I/OFile I/OALLEGRO_FILEAn opaque object representing an open file. This could be a real file on disk or a virtual file. ALLEGRO_FILE_INTERFACEA structure containing function pointers to handle a type of "file", real or virtual. See the full discussion in al_set_new_file_interface. ALLEGRO_SEEK
al_fopenCreates and opens a file (real or virtual) given the path and mode. The current file interface is used to open the file. 'path' - the path to open 'mode' - mode to open the entry in ("r", "w", etc.) Depending on the stream type and the mode string, files may be opened in "text" mode. The handling of newlines is particularly important. For example, using the default stdio-based streams on DOS and Windows platforms, where the native end-of-line terminators are CR+LF sequences, a call to al_fgetc may return just one character ('\n') where there were two bytes (CR+LF) in the file. When writing out '\n', two bytes would be written instead. (As an aside, '\n' is not defined to be equal to LF either.) Newline translations can be useful for text files but is disastrous for binary files. To avoid this behaviour you need to open file streams in binary mode by using a mode argument containing a "b", e.g. "rb", "wb". See also: al_set_new_file_interface. al_fcloseClose the given file. al_freadRead 'size' bytes into 'ptr' from entry 'fp' Return number of bytes actually read. al_fwriteWrite '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. al_fflushFlush 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 al_ftellReturns 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 al_fseekSeek to 'offset' in file based on 'whence'. 'whence' can be:
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 al_feofReturns true if the end-of-file indicator has been set on the file, i.e. we have attempted to read past the end of the file. This does not return true if we simply are at the end of the file. The following code correctly reads two bytes, even when the file contains exactly two bytes: al_ferrorReturns true if there was some sort of previous error. al_fungetcUngets 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 al_fsizeReturn the size of the file, if it can be determined, or -1 otherwise. al_fgetcRead and return next byte in entry 'f'. Returns EOF on end of file or if an error occurred. al_fputcWrite a single byte to entry. Parameters:
Returns: EOF on error al_fread16leReads a 16-bit word in little-endian format (LSB first). Returns: The read 16-bit word or EOF on error al_fread16beReads a 16-bit word in big-endian format (MSB first). Returns: The read 16-bit word or EOF on error. al_fwrite16leWrites a 16-bit word in little-endian format (LSB first). Returns the number of bytes written: 2 on success, less than 2 on an error. al_fwrite16beWrites a 16-bit word in big-endian format (MSB first). Returns the number of bytes written: 2 on success, less than 2 on an error. al_fread32leReads a 32-bit word in little-endian format (LSB first). If 'ret_success' is not NULL, it will be set to true on success or false on failure. Returns the read 32-bit word. 'ret_success' indicates if a full 32-bit word was read before reaching the EOF or an error. al_fread32beRead a 32-bit word in big-endian format (MSB first). If 'ret_success' is not NULL, it will be set to true on success or false on failure. Returns: The read 32-bit word. 'ret_success' indicates if a full 32-bit word was read before reaching the EOF or an error. al_fwrite32leWrites a 32-bit word in little-endian format (LSB first). Returns the number of bytes written: 4 on success, less than 4 on an error. al_fwrite32beWrites a 32-bit word in big-endian format (MSB first). Returns the number of bytes written: 4 on success, less than 4 on an error. al_fgetsRead a string of bytes terminated with a newline or end-of-file into the buffer given. The line terminator(s), if any, are included in the returned string. A maximum of max-1 bytes are read, with one byte being reserved for a NUL terminator. Parameters:
Returns the pointer to buf on success. Returns NULL if an error occurred or if the end of file was reached without reading any bytes. See al_fopen about translations of end-of-line characters. al_fget_ustrRead a string of bytes terminated with a newline or end-of-file. The line terminator(s), if any, are included in the returned string. On success returns a pointer to a new ALLEGRO_USTR structure. This must be freed eventually with al_ustr_free. Returns NULL if an error occurred or if the end of file was reached without reading any bytes. See al_fopen about translations of end-of-line characters. al_fputsWrites a string to file. Apart from the return value, this is equivalent to: Parameters:
Returns a non-negative integer on success, EOF on error. Note: depending on the stream type and the mode passed to al_fopen, newline characters in the string may or may not be automatically translated to native end-of-line sequences, e.g. CR/LF instead of LF. Standard I/O specific routinesal_fopen_fdCreate an ALLEGRO_FILE object that operates on an open file descriptor using stdio routines. See the documentation of fdopen() for a description of the 'mode' argument. Returns an ALLEGRO_FILE object on success or NULL on an error. On an error, the Allegro errno will be set and the file descriptor will not be closed. The file descriptor will be closed by al_fclose so you should not call close() on it. al_make_temp_fileMake a temporary randomly named file given a filename 'template'. '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 characters. There should be no path separators. If 'ret_path' is not NULL, the address it points to will be set to point to a new path structure with the name of the temporary file. Returns the opened ALLEGRO_FILE on success, NULL on failure. Alternative file streamsBy default, the Allegro file I/O routines use the C library I/O routines, hence work with files on the local filesystem, but can be overridden so that you can read and write to other streams. For example, you can work with block of memory or sub-files inside .zip files. There are two ways to get an ALLEGRO_FILE that doesn't use stdio. An addon library may provide a function that returns a new ALLEGRO_FILE directly, after which, all al_f* calls on that object will use overridden functions for that type of stream. Alternatively, al_set_new_file_interface changes which function will handle the following al_fopen calls for the current thread. al_set_new_file_interfaceSet the ALLEGRO_FILE_INTERFACE table for the calling thread. This will change the handler for later calls to al_fopen. See also: al_store_state, al_restore_state. al_get_new_file_interfaceReturn a pointer to the ALLEGRO_FILE_INTERFACE table in effect for the calling thread. See also: al_store_state, al_restore_state. |
Last updated: 2009-07-05 05:34:17 UTC