File I/O


Defines

#define MAX_NAME_LEN   64
#define FS_NONE   0
#define FS_CREATED   1
#define FS_REMOVED   2
#define FC_CHANGED   3
#define FC_RENAMED   4
#define FC_FORMATTED   5
#define SEEK_SET   0
#define SEEK_CUR   1
#define SEEK_END   2

Typedefs

typedef int seek_t

Enumerations

enum  Flags {
  FLAG_BAD = 1,
  FLAG_EOF = 2,
  FLAG_EXCEPTIONS = 4
}

Functions

struct Inputopen_resource (int index)
struct Inputopen_resource_Ex (char *sz_file_name)
int mFileName_max_file_name_length (void)
bool mFileName_is_valid_file_name (char *sz_full_name)
void mFileName_split_path (char *sz_full_name, char *sz_device_name, char *sz_file_name)
void mFileName_make_path (char *sz_full_name, char *sz_device_name, char *sz_file_name)
void mFileName_get_path (char *sz_full_name, char *sz_path)
char* mFileName_current_device_name (void)

Variables

char MP3_DRIVE_NAME []
char DEFAULT_DRIVE_NAME []
char DRIVE_A_NAME []
char DRIVE_B_NAME []


Compounds

     struct   ArchiveArchive storage. A file that holds more files inside, each one of may be compressed
     struct   FileThe object to be manipulated
     struct   FileFindFile finder. Implements the functions needed to find a set of files
     struct   FileInputThe Input file stream
     struct   FileOutputThe Output file stream
     struct   InputAn abstract object for sequential data access objects
     struct   OutputAn abstract object for the sequential data access objects


Detailed Description

Structures of the File I/O section define the most basic file operations in the CyOS. These rules apply to file names that include any of these valid symbols:
valid_symbols = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM 1234567890-_+.()";
start_disabled = " -+.";
end_disabled = " -+.";


Define Documentation

#define FC_CHANGED   3
 

File was changed.

#define FC_FORMATTED   5
 

Disk was formatted.

#define FC_RENAMED   4
 

File was renamed.

#define FS_CREATED   1
 

File was created.

#define FS_NONE   0
 

State is undefined.

#define FS_REMOVED   2
 

File was removed.

#define MAX_NAME_LEN   64
 

Maximum filename length.

#define SEEK_CUR   1
 

Seek from the current position (a positive offset indicates towards end of file).

#define SEEK_END   2
 

Seek from the end.
A negative offset indicates closer to the beginning of the file; zero offset means set after the last byte of the file.

#define SEEK_SET   0
 

Seek to the absolute position.


Typedef Documentation

typedef int seek_t
 

Defines the initial position in the stream and must be one of the following: SEEK_SET, SEEK_CUR or SEEK_END.

See also:
SEEK_SET, SEEK_CUR, SEEK_END.


Enumeration Type Documentation

enum Flags
 

Stream's state flags.
Stream state is represented by setting and clearing following flags:

Enumeration values:
FLAG_BAD   is set if the stream object is invalid.
FLAG_EOF   is set when the stream reaches the end of the file.
FLAG_EXCEPTIONS   indicates that implementation must throw exceptions on errors.


Function Documentation

char * mFileName_current_device_name ( void )
 

Retrieves the name of the current flash device.

Returns:
Name of the current flash device.
       #include <cybiko.h>
       ...
       int index;
       char* sz_tmp_full_name;
       char sz_tmp_name[16]; 
       int max_file_name = mFileName_max_file_name_length();
       ...
       //  Generates name for the temporary file;
       sz_tmp_full_name = (char*) malloc( max_file_name );
       do
       {
         sprintf( sz_tmp_name, "%ld.tmp", time() );  
         mFileName_make_path( sz_tmp_full_name, 
                              mFileName_current_device_name(),
                              sz_tmp_name );
       }while( ! mFileName_is_valid_file_name( sz_tmp_full_name ) );
       ...
       free( sz_tmp_full_name );
       ...

void mFileName_get_path ( char * sz_full_name,
char * sz_path )
 

Retrieves the path to the file from the absolute file name.

Parameters:
sz_full_name   absolute name of the file.
sz_path   buffer in which the file path will be stored.
Returns:
None.
       #include <cybiko.h>
       ...
       struct module_t main_module;
       char* sz_application_path;
       ...
       init_module( &main_module );
       ...
       //  Retrieves application name.
       sz_application_path = (char*) malloc( mFileName_max_file_name_length() );
       mFileName_get_path( Archive_archive_name( main_module.m_process->module->archive ), 
                           sz_application_path );
       ...
       TRACE("Path to the application is %s", sz_application_path );
       ...
       free(sz_application_path);

bool mFileName_is_valid_file_name ( char * sz_full_name )
 

Verifies that the file name is valid.

Parameters:
sz_full_name   absolute name of the file.
Returns:
TRUE if name of the file is valid.
       #include <cybiko.h>
       ...
       int index;
       char* sz_tmp_full_name;
       char sz_tmp_name[16]; 
       int max_file_name = mFileName_max_file_name_length();
       ...
       //  Generates name for the temporary file;
       sz_tmp_full_name = (char*) malloc( max_file_name );
       do
       {
         sprintf( sz_tmp_name, "%ld.tmp", time() );  
         mFileName_make_path( sz_tmp_full_name, 
                              mFileName_current_device_name(),
                              sz_tmp_name );
       }while( ! mFileName_is_valid_file_name( sz_tmp_full_name ) );
       ...
       free( sz_tmp_full_name );
       ...

void mFileName_make_path ( char * sz_full_name,
char * sz_device_name,
char * sz_file_name )
 

Creates an absolute file name by combining the file name with the device name.

Parameters:
sz_full_name   buffer in which the absolute file name will be stored.
sz_device_name   device name.
sz_file_name   file name.
Returns:
None.
       #include <cybiko.h>
       ...
       int index;
       char* sz_tmp_full_name;
       char sz_tmp_name[16]; 
       int max_file_name = mFileName_max_file_name_length();
       ...
       //  Generates name for the temporary file;
       sz_tmp_full_name = (char*) malloc( max_file_name );
       do
       {
         sprintf( sz_tmp_name, "%ld.tmp", time() );  
         mFileName_make_path( sz_tmp_full_name, 
                              mFileName_current_device_name(),
                              sz_tmp_name );
       }while( ! mFileName_is_valid_file_name( sz_tmp_full_name ) );
       ...
       free( sz_tmp_full_name );
       ...

int mFileName_max_file_name_length ( void )
 

Retrieves the maximum file name length.

Returns:
Maximum length of the file name.
       #include <cybiko.h>
       ...
       int index;
       char* sz_tmp_full_name;
       char sz_tmp_name[16]; 
       int max_file_name = mFileName_max_file_name_length();
       ...
       //  Generates name for the temporary file;
       sz_tmp_full_name = (char*) malloc( max_file_name );
       do
       {
         sprintf( sz_tmp_name, "%ld.tmp", time() );  
         mFileName_make_path( sz_tmp_full_name, 
                              mFileName_current_device_name(),
                              sz_tmp_name );
       }while( ! mFileName_is_valid_file_name( sz_tmp_full_name ) );
       ...
       free( sz_tmp_full_name );
       ...

void mFileName_split_path ( char * sz_full_name,
char * sz_device_name,
char * sz_file_name )
 

Splits the absolute file name into device name and file name.

Parameters:
sz_full_name   absolute file name.
sz_device_name   buffer in which the device name will be stored.
sz_file_name   buffer in which the file name will be stored.
Returns:
None.
       #include <cybiko.h>
       ...
       struct module_t main_module;
       char* sz_application_name;
       ...
       init_module( &main_module );
       ...
       //  Retrieves application name.
       sz_application_name = (char*) malloc( mFileName_max_file_name_length() );
       mFileName_split_path( Archive_archive_name( main_module.m_process->module->archive ), 
                             NULL,
                             sz_application_name );
       ...
       TRACE("Name of the application is %s", sz_application_name );
       ...
       free(sz_application_name);

struct Input * open_resource ( int index )
 

Returns the resource from the current archive, using resource index.

Returns:
Pointer to the initialized Input object.
       #include <cybiko.h>
       ...
       struct Input* ptr_input;
       struct Bitmap bmp;
       ...
       Bitmap_ctor(&bmp);
       ...
       //  Your make file must have the archive resource "bmp.pic" linked 
       //  by the filer. "bmp.pic" must be the first in the resource 
       //  list (index = 0). For example, see the Cybiko Compiler's 
       //  Introduction Section
       ptr_input = open_resource( 0 );
       if( !Bitmap_load( &bmp, ptr_input ) )
           return FALSE;
       else
           ...
       Bitmap_dtor( &bmp, LEAVE_MEMORY );
       Input_dtor( ptr_input, FREE_MEMORY );
       ...
See also:
open_resource_Ex.

struct Input * open_resource_Ex ( char * sz_file_name )
 

Returns the resource from the current archive, using the resource name.

Returns:
Pointer to the initialized Input object.
       #include <cybiko.h>
       ...
       struct Input* ptr_input;
       struct Bitmap bmp;
       ...
       Bitmap_ctor(&bmp);
       ...
       //  Your make file must have the archive resource "bmp.pic" linked 
       //  by filer. For example, see the Cybiko Compiler's 
       //  Introduction Section
       ptr_input = open_resource_Ex( "bmp.pic" );
       if( !Bitmap_load( &bmp, ptr_input ) )
           return FALSE;
       else
           ...
       Bitmap_dtor( &bmp, LEAVE_MEMORY );
       Input_dtor( ptr_input, FREE_MEMORY );
       ...
See also:
open_resource.


Variable Documentation

char DEFAULT_DRIVE_NAME[]
 

Name of the default flash device.

       #include <cybiko.h>
       ...
       TRACE( "Names of the devices:" );
       TRACE( "\tMp3 player: %s", MP3_DRIVE_NAME );
       TRACE( "\tDrive A: %s", DRIVE_A_NAME );
       TRACE( "\tDrive B: %s", DRIVE_B_NAME );
       TRACE( "\tDefault Drive: %s", DEFAULT_DRIVE_NAME );
       ...

char DRIVE_A_NAME[]
 

Name of flash device A.

       #include <cybiko.h>
       ...
       TRACE( "Names of the devices:" );
       TRACE( "\tMp3 player: %s", MP3_DRIVE_NAME );
       TRACE( "\tDrive A: %s", DRIVE_A_NAME );
       TRACE( "\tDrive B: %s", DRIVE_B_NAME );
       TRACE( "\tDefault Drive: %s", DEFAULT_DRIVE_NAME );
       ...

char DRIVE_B_NAME[]
 

Name of flash device B.

       #include <cybiko.h>
       ...
       TRACE( "Names of the devices:" );
       TRACE( "\tMp3 player: %s", MP3_DRIVE_NAME );
       TRACE( "\tDrive A: %s", DRIVE_A_NAME );
       TRACE( "\tDrive B: %s", DRIVE_B_NAME );
       TRACE( "\tDefault Drive: %s", DEFAULT_DRIVE_NAME );
       ...

char MP3_DRIVE_NAME[]
 

Name of MP3 player device.

       #include <cybiko.h>
       ...
       TRACE( "Names of the devices:" );
       TRACE( "\tMp3 player: %s", MP3_DRIVE_NAME );
       TRACE( "\tDrive A: %s", DRIVE_A_NAME );
       TRACE( "\tDrive B: %s", DRIVE_B_NAME );
       TRACE( "\tDefault Drive: %s", DEFAULT_DRIVE_NAME );
       ...