GrafX2 2.9.3227
The ultimate 256-color painting program
File system

filesystem operations More...

Typedefs

typedef void T_File_dir_cb(void *pdata, const char *filename, const word *unicode_filename, byte is_file, byte is_directory, byte is_hidden)
 

Functions

unsigned long File_length (const char *fname)
 Size of a file, in bytes. Returns 0 in case of error. 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. Full name (with directories) is optional. More...
 
void For_each_file (const char *directory_name, void Callback(const char *full_name, const char *file_name))
 Scans a directory, calls Callback for each file in it,. More...
 
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...
 
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...
 

Detailed Description

filesystem operations

Typedef Documentation

◆ T_File_dir_cb

typedef void T_File_dir_cb(void *pdata, const char *filename, const word *unicode_filename, byte is_file, byte is_directory, byte is_hidden)

Function Documentation

◆ File_length()

unsigned long File_length ( const char *  fname)

Size of a file, in bytes. Returns 0 in case of error.

Referenced by Load_TIFF(), and Test_Read_Write_bytes().

◆ File_exists()

int File_exists ( const char *  fname)

◆ Directory_exists()

int Directory_exists ( const char *  directory)

Returns true if a directory passed as a parameter exists in the current directory.

References NULL, and PARENT_DIR.

Referenced by Button_Load_or_Save(), Get_config_directory(), and Test_File_exists().

◆ Directory_create()

int Directory_create ( const char *  directory)

Creates a directory.

Returns
0 on success, -1 on error

References NULL.

Referenced by Get_config_directory().

◆ File_is_hidden()

int File_is_hidden ( const char *  fname,
const char *  full_name 
)

Check if a file or directory is hidden. Full name (with directories) is optional.

Check if a file or directory is hidden. Full name (with directories) is optional.

References NULL, and PARENT_DIR.

Referenced by For_each_directory_entry().

◆ For_each_file()

void For_each_file ( const char *  directory_name,
void   Callbackconst char *full_name, const char *file_name 
)

Scans a directory, calls Callback for each file in it,.

◆ For_each_directory_entry()

void For_each_directory_entry ( const char *  directory_name,
void *  pdata,
T_File_dir_cb  Callback 
)

◆ Create_lock_file()

byte Create_lock_file ( const char *  file_directory)

Creates a lock file, to check if an other instance of Grafx2 is running.

Returns
0 on success (first instance), -1 on failure (others are running)

References Filepath_append_to_dir(), GFX2_LOCK_FILENAME, Lock_file_handle, and NULL.

Referenced by Check_recovery().

◆ Release_lock_file()

void Release_lock_file ( const char *  file_directory)

◆ Get_current_directory()

char * Get_current_directory ( char *  buf,
word **  unicode,
size_t  size 
)

Return the current directory, equivalent to getcwd()

Parameters
bufdestination buffer. can be NULL
unicodedestination pointer for the unicode version of the path
sizedestination buffer size, ignored if buf is NULL
Returns
NULL for error, buf or a malloc'ed buffer

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().

◆ Change_directory()

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().

◆ Remove_path()

◆ Remove_directory()

int Remove_directory ( const char *  path)

Remove the directory.

Referenced by Button_Load_or_Save().

◆ Calculate_relative_path()

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().