File Struct Reference


Public Methods

struct File* File_ctor (struct File *ptr_file)
struct File* File_ctor_Ex (struct File *ptr_file, char *sz_file_name)
bool File_is_free (struct File *ptr_file)
time_t File_get_date (struct File *ptr_file)
bool File_set_date (struct File *ptr_file, time_t date)
bool File_get_info (struct File *ptr_file, char *sz_file_name)
long File_free_bytes_total (char *sz_device_name)
long File_free_user_bytes_total (char *sz_device_name)
long File_files_total (char *sz_device_name)
long File_bytes_total (char *sz_device_name)
long File_blocks_total (char *sz_device_name)
long File_bad_blocks_total (char *sz_device_name)
int File_block_size (char *sz_device_name)
long File_free_blocks_total (char *sz_device_name)
bool File_bootable (char *sz_device_name)
bool File_is_valid_name (char *sz_file_name)
bool File_rename (char *sz_old_filename, char *sz_new_filename)
bool File_remove (char *sz_file_name)
bool File_exists (char *sz_file_name)
void File_dtor (struct File *ptr_file, int memory_flag)

Public Attributes

char name [MAX_NAME_LEN]
long size
time_t modification_time


Detailed Description

Object for manipulation files.

See also:
File I/O


Member Function Documentation

long File_bad_blocks_total ( char * sz_device_name )
 

Returns the total number of bad blocks on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The total number of bad blocks on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_blocks_total.

int File_block_size ( char * sz_device_name )
 

Returns the block size for the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The block size for the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...

long File_blocks_total ( char * sz_device_name )
 

Returns the total number of blocks on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The total number of blocks on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_bad_blocks_total.

bool File_bootable ( char * sz_device_name )
 

Returns TRUE if the specified device is bootable.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
TRUE if the specified device is bootable
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...

long File_bytes_total ( char * sz_device_name )
 

Returns the total number of bytes on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The total number of bytes on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_files_total.

struct File * File_ctor ( struct File * ptr_file )
 

Creates an empty File object.

Parameters:
ptr_file   A pointer to the File structure
Returns:
A pointer to the initialized File object
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file );
       if( File_get_info( &file, "share_data.txt" ) 
           && File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
       }
       ...
       File_dtor( &file, LEAVE_MEMORY );
       ...
See also:
File_ctor_Ex.

struct File * File_ctor_Ex ( struct File * ptr_file,
char * sz_file_name )
 

Extended version of the File_ctor function.
Creates a File object and initializes it, using the specified file's parameters.

Parameters:
ptr_file   A pointer to the File structure
sz_file_name   The name of the file with which to initialize the File object
Returns:
A pointer to the initialized File object.
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file, "share_data.txt" );
       if( File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
       }
       ...
       File_dtor( &file, LEAVE_MEMORY );
       ...
See also:
File_ctor.

void File_dtor ( struct File * ptr_file,
int memory_flag )
 

Destructor.

Parameters:
ptr_file   A pointer to the initialized File object.
memory_flag   Can be FREE_MEMORY or LEAVE_MEMORY. If the memory was allocated for the object by malloc(), use FREE_MEMORY to free it. Use LEAVE_MEMORY If the object was static or allocated in a stack
Returns:
None
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file );
       if( File_get_info( &file, "share_data.txt" ) 
           && File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
       }
       ...
       File_dtor( &file, LEAVE_MEMORY ); 
       ...
See also:
FREE_MEMORY, LEAVE_MEMORY.

bool File_exists ( char * sz_file_name )
 

Checks whether a file with specified name exists.

Parameters:
sz_file_name   The file name to check.
Returns:
TRUE if the file with the specified name exists, otherwise FALSE
       #include <cybiko.h>
       ...
       if( File_exists( "save.dat" ) )
       {
         //  Load unfinished game.
         ...
       }
       ...
       if( game_finished )
       {
         File_remove( "save.dat" );
       }
       ...

long File_files_total ( char * sz_device_name )
 

Returns the total number of files on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The total number of files on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_bytes_total.

long File_free_blocks_total ( char * sz_device_name )
 

Returns the number of free blocks on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
The number of free blocks on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...

long File_free_bytes_total ( char * sz_device_name )
 

Estimates the number of free bytes on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
Number of free bytes on the specified device
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_free_user_bytes_total.

long File_free_user_bytes_total ( char * sz_device_name )
 

Estimates the number of free bytes for user data on the specified device.

Parameters:
sz_device_name   The device name (or "" for local flash memory)
Returns:
Number of free bytes on the specified device for user data
       #include <cybiko.h>
       ...
       TRACE( "------Flash Info---------" );
       TRACE( "Bytes total on your device : %ld ", File_bytes_total( "" ) );
       TRACE( "Block size : %ld ", File_block_size( "" ) );
       TRACE( "Blocks total on your device : %ld ", File_blocks_total( "" ) );
       TRACE( "Free blocks total on your device : %ld ", File_free_blocks_total( "" ) );
       TRACE( "Bad blocks total on your device : %ld ", File_bad_blocks_total( "" ) );
       TRACE( "Free bytes total on your device : %ld ", File_free_bytes_total( "" ) );
       TRACE( "Free bytes for user needs on your device : %ld ", File_free_user_bytes_total( "" ) );
       TRACE( "File number on your device  : %ld ", File_files_total( "" ) );
       TRACE( "Device is %s ", File_bootable("") ? "bootable" : "not bootable" );
       ...
See also:
File_free_bytes_total.

time_t File_get_date ( struct File * ptr_file )
 

Returns the time the file was last modified.

Parameters:
ptr_file   A pointer to the initialized File object
Returns:
The time the file was last modified
       #include <cybiko.h>
       ...
       struct File file;
       struct Time file_time;
       ...
       {
         File_ctor( &file );
         if( File_get_info( &file, "share_data.txt" ) 
             && File_is_free( &file ) )
         {
           Time_decode( &file_time, File_get_date( &file ) );
           TRACE("Date of modification is  %d.%d.%d",
                  file_time.month,
                  file_time.day,
                  file_time.year + 1990 );
         }
         ...
         File_dtor( &file, LEAVE_MEMORY );
       }
       ...
See also:
File_set_date.

bool File_get_info ( struct File * ptr_file,
char * sz_file_name )
 

Initializes the File object's fields (name, date, length) of the File object, using the specified file's parameters.

Parameters:
ptr_file   A pointer to the initialized File object
sz_file_name   The name of the file with which to initialize the File object
Returns:
FALSE if the file is not found
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file );
       if( File_get_info( &file, "share_data.txt" ) 
           && File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
       }
       ...
       File_dtor( &file, LEAVE_MEMORY );
       ...

bool File_is_free ( struct File * ptr_file )
 

Checks whether a file is open for IO functions.

Parameters:
ptr_file   A pointer to the initialized File object
Returns:
TRUE if the file is open for IO functions
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file );
       if( File_get_info( &file, "share_data.txt" ) 
           && File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
       }
       ...
       File_dtor( &file, LEAVE_MEMORY );
       ...

bool File_is_valid_name ( char * sz_file_name )
 

Returns TRUE if the specified string is valid as a filename.

Parameters:
sz_file_name   The file's name
Returns:
TRUE if the specified string is valid as a file name
       #include <cybiko.h>
       ...
       char* input_new_file_name();
       ...
       if( File_is_valid_name( input_new_file_name() ) )
       {
         //  Creating new file.
         ...
       }
       ...

bool File_remove ( char * sz_file_name )
 

Deletes the specified file if it is not being modified (written to or read).

Parameters:
sz_file_name   The file's name
Returns:
TRUE if the file is successfully removed, otherwise FALSE
       #include <cybiko.h>
       ...
       if( File_exists( "save.dat" ) )
       {
         //  Loads unfinished game.
         ...
       }
       ...
       if( game_finished )
       {
         File_remove( "save.dat" );
       }
       ...

bool File_rename ( char * sz_old_filename,
char * sz_new_filename )
 

Renames the specified file if it is not being modified (written to or read).

Parameters:
sz_old_filename   Old file name
sz_new_filename   New file name
Returns:
TRUE if the file is successfully renamed, otherwise FALSE
       #include <cybiko.h>
       ...
       if( File_exists( "last_game.sav" ) )
       {
         File_rename( "last_game.sav", "prev_game.sav" );
       }
       ...

bool File_set_date ( struct File * ptr_file,
time_t date )
 

Sets date the file was last modified.

Parameters:
ptr_file   A pointer to the initialized File object
date   A date the file was last modified
Returns:
TRUE if the time set was successful
       #include <cybiko.h>
       ...
       struct File file;
       ...
       File_ctor( &file );
       if( File_get_info( &file, "share_data.txt" ) 
           && File_is_free( &file ) )
       {
         //  Performs IO operations.
         ...
         //  Updates the date of the last modifications.
         File_set_date( &file, time() );
       }
       ...
       File_dtor( &file, LEAVE_MEMORY );
       ...
See also:
File_get_date.


Member Data Documentation

time_t modification_time
 

Time of the last modification.

char name[MAX_NAME_LEN]
 

File name.

long size
 

File size.