|
GrafX2 2.9.3227
The ultimate 256-color painting program
|
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <errno.h>#include <fcntl.h>#include <limits.h>#include <unistd.h>#include <dirent.h>#include "struct.h"#include "io.h"#include "realpath.h"#include "unicode.h"#include "global.h"#include "gfx2log.h"#include "gfx2mem.h"#include "fileseltools.h"
Include dependency graph for io.c:Macros | |
| #define | GFX2_LOCK_FILENAME "gfx2.lck" |
Functions | |
| int | Read_byte (FILE *file, byte *dest) |
| Reads a single byte from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Write_byte (FILE *file, byte b) |
| Writes a single byte to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_bytes (FILE *file, void *dest, size_t size) |
| Reads several bytes from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_byte_line (FILE *file, char *line, size_t size) |
| int | Write_bytes (FILE *file, const void *src, size_t size) |
| Writes several bytes to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_word_le (FILE *file, word *dest) |
| Reads a 16-bit Low-Endian word from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Write_word_le (FILE *file, word w) |
| Writes a 16-bit Low-Endian word to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_word_be (FILE *file, word *dest) |
| Reads a 16-bit Big-Endian word from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Write_word_be (FILE *file, word w) |
| Writes a 16-bit Big-Endian word to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_dword_le (FILE *file, dword *dest) |
| Reads a 32-bit Low-Endian dword from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Write_dword_le (FILE *file, dword dw) |
| Writes a 32-bit Low-Endian dword to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Read_dword_be (FILE *file, dword *dest) |
| Reads a 32-bit Big-Endian dword from an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| int | Write_dword_be (FILE *file, dword dw) |
| Writes a 32-bit Big-Endian dword to an open file. Returns true if OK, false if a file i/o error occurred. More... | |
| char * | Find_last_separator (const char *str) |
| Finds the rightmost path separator in a full filename. Used to separate directory from file. More... | |
| word * | Find_last_separator_unicode (const word *str) |
| Finds the rightmost path separator in a full filename in unicode. Used to separate directory from file. More... | |
| char * | Filepath_append_to_dir (const char *dir, const char *filename) |
| Construct full file path. More... | |
| char * | Extract_filename (const char *source) |
| Extracts the filename part from a full file name. More... | |
| char * | Extract_path (const char *source) |
| Extracts the directory from a full file name. More... | |
| void | Append_path (char *path, const char *filename, char *reverse_path) |
| Appends a file or directory name to an existing directory name. More... | |
| int | Position_last_dot (const char *fname) |
| finds the rightmost '.' character in fullname. Used to find file extension. returns -1 if not found More... | |
| int | Position_last_dot_unicode (const word *fname) |
| finds the rightmost '.' character in fullname. Used to find file extension. returns -1 if not found More... | |
| int | File_exists (const char *fname) |
| Returns true if a file passed as a parameter exists in the current directory. More... | |
| int | Directory_exists (const char *directory) |
| Returns true if a directory passed as a parameter exists in the current directory. More... | |
| int | Directory_create (const char *directory) |
| Creates a directory. More... | |
| int | File_is_hidden (const char *fname, const char *full_name) |
| Check if a file or directory is hidden. More... | |
| unsigned long | File_length (const char *fname) |
| Size of a file, in bytes. Returns 0 in case of error. More... | |
| unsigned long | File_length_file (FILE *file) |
| Size of an open file, in bytes. More... | |
| void | For_each_file (const char *directory_name, void Callback(const char *, const char *)) |
| void | For_each_directory_entry (const char *directory_name, void *pdata, T_File_dir_cb Callback) |
| Scans a directory, calls Callback for each file or directory in it,. More... | |
| word * | Get_Unicode_Filename (word *filename_unicode, const char *filename, const char *directory) |
| Convert a file name to unicode characters. More... | |
| byte | Create_lock_file (const char *file_directory) |
| Creates a lock file, to check if an other instance of Grafx2 is running. More... | |
| void | Release_lock_file (const char *file_directory) |
| Release a lock file created by Create_lock_file. More... | |
| char * | Get_current_directory (char *buf, word **unicode, size_t size) |
| Return the current directory, equivalent to getcwd() More... | |
| int | Change_directory (const char *path) |
| Change current directory. return 0 for success, -1 in case of error. More... | |
| int | Remove_path (const char *path) |
| Remove the file. More... | |
| int | Remove_directory (const char *path) |
| Remove the directory. More... | |
| char * | Calculate_relative_path (const char *ref_path, const char *path) |
| Calculate relative path. More... | |
Variables | |
| int | Lock_file_handle = -1 |
| Lock file used to prevent several instances of grafx2 from harming each others' backups. More... | |
| #define GFX2_LOCK_FILENAME "gfx2.lck" |
| void Append_path | ( | char * | path, |
| const char * | filename, | ||
| char * | reverse_path | ||
| ) |
Appends a file or directory name to an existing directory name.
As a special case, when the new item is equal to PARENT_DIR, this will remove the rightmost directory name. reverse_path is optional, if it's non-null, the function will write there :
References Find_last_separator(), PARENT_DIR, and PATH_SEPARATOR.
| void For_each_file | ( | const char * | directory_name, |
| void | Callbackconst char *, const char * | ||
| ) |
References Filepath_append_to_dir(), GFX2_Log(), GFX2_WARNING, NULL, and Realpath().
Referenced by Button_Skins(), Check_recovery(), Delete_safety_backups(), Init_text(), and Load_Unicode_fonts().
| void Release_lock_file | ( | const char * | file_directory | ) |
Release a lock file created by Create_lock_file.
References Filepath_append_to_dir(), GFX2_LOCK_FILENAME, Lock_file_handle, and Remove_path().
Referenced by Delete_safety_backups().
| char * Get_current_directory | ( | char * | buf, |
| word ** | unicode, | ||
| size_t | size | ||
| ) |
Return the current directory, equivalent to getcwd()
| buf | destination buffer. can be NULL |
| unicode | destination pointer for the unicode version of the path |
| size | destination buffer size, ignored if buf is NULL |
References GFX2_ERROR, GFX2_Log(), GFX2_malloc, MAX_PATH_CHARACTERS, NULL, and PATH_SEPARATOR.
Referenced by Button_Load_or_Save(), Get_program_directory(), Init_program(), and Read_list_of_files().
| int Change_directory | ( | const char * | path | ) |
Change current directory. return 0 for success, -1 in case of error.
References GFX2_DEBUG, and GFX2_Log().
Referenced by Button_Load_or_Save(), Delete_safety_backups(), and Program_shutdown().
| int Remove_path | ( | const char * | path | ) |
Remove the file.
Referenced by Backup_existing_file(), Button_Load_or_Save(), Release_lock_file(), Remove_file(), Rotate_safety_backups(), Test_File_exists(), Test_Read_Write_byte(), Test_Read_Write_bytes(), Test_Read_Write_dword(), Test_Read_Write_word(), and Test_Realpath().
| int Remove_directory | ( | const char * | path | ) |
Remove the directory.
Referenced by Button_Load_or_Save().
| char * Calculate_relative_path | ( | const char * | ref_path, |
| const char * | path | ||
| ) |
Calculate relative path.
References GFX2_malloc, NULL, PATH_SEPARATOR, and Realpath().
Referenced by Button_Load_or_Save(), and Test_Calculate_relative_path().
| int Lock_file_handle = -1 |
Lock file used to prevent several instances of grafx2 from harming each others' backups.
Referenced by Create_lock_file(), and Release_lock_file().