libarmutils  1.4
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups
File Utils

Macros

#define FC_CHECK_MD5   0x1
 use md5 validation when copying a file

Functions

int file_copy (const char *src_file, const char *dest_file, int flags)
 Copy a file.
int file_exists (const char *file)
 Check if a file exists.
char * file_get_md5 (const char *file, char *hexdigest)
 Get the MD5 of a file.
int file_move (const char *src_file, const char *dest_file, int use_md5_validation)
 Move a file.
void * file_mmap (const char *file, size_t *map_size)
 Create a memory map of a file for reading.
int file_munmap (void *map_addr, size_t map_size)
 Remove a memory map created to read a file.

Detailed Description


Function Documentation

int file_copy ( const char *  src_file,
const char *  dest_file,
int  flags 
)

Copy a file.

This function will prepend the destination file with a '.' and add a '.lck' extenstion to it while the file is being copied. When the copy has been completed successfuly the rename function is used to remove the '.' prefix and '.lck' extension.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
src_file- path to the source file
dest_file- path to the destination file
flags- control flags

Control Flags:

  • FC_CHECK_MD5 = Use MD5 validation.
Returns:
  • 1 if the file copy was successful
  • 0 if an error occurred

Definition at line 74 of file file_utils.c.

int file_exists ( const char *  file)

Check if a file exists.

Parameters:
file- path to the file
Returns:
  • 1 if the file exists
  • 0 if the file does not exist

Definition at line 303 of file file_utils.c.

char* file_get_md5 ( const char *  file,
char *  hexdigest 
)

Get the MD5 of a file.

The hexdigest buffer must be large enough to hold 33 characters (32 for the hex value plus one for the string terminator).

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
file- path to the file
hexdigest- buffer to store the MD5 hexdigext value
Returns:
  • pointer to the hexdigest buffer
  • NULL if an error occurred

Definition at line 328 of file file_utils.c.

void* file_mmap ( const char *  file,
size_t *  map_size 
)

Create a memory map of a file for reading.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
file- path to the file
map_size- returns the size of the memory mapped file
Returns:
  • address of the memory map
  • (void *)-1 if an error occurred

Definition at line 488 of file file_utils.c.

int file_move ( const char *  src_file,
const char *  dest_file,
int  flags 
)

Move a file.

This function will first attempt to simply rename the file. If the rename fails because the file is being moved across file systems, the file_copy() function will be used and the source file deleted.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
src_file- path to the old file name
dest_file- path to the new file name
flags- control flags

Control Flags:

  • FC_CHECK_MD5 = Use MD5 validation. This flag will be ignored unless it is necessary to copy and delete the file in order to move it.
Returns:
  • 1 if the file was moved
  • 0 if an error occurred

Definition at line 405 of file file_utils.c.

int file_munmap ( void *  map_addr,
size_t  map_size 
)

Remove a memory map created to read a file.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
map_addr- address of the memory map
map_size- size of the memory mapped file
Returns:
  • 1 if successful
  • 0 if an error occurred

Definition at line 545 of file file_utils.c.