File I/O Library Module

The file i/o library module has the file name fio.c. This module performs file input/output operations. File i/o is mostly stream oriented.

Here is a list of functions in the file i/o library module:

Module Dependencies

This module does not depend on any other module and may be used by itself.

Module Header Files

This module requires the header file fio.h which is automatically included from the header file enhlib.h which is automatically included from header file stdhead.h.

Module Functions

unique

Prototype  : int unique(char *dir, char *fname)
Parameters :
      Name : dir
Description: directory path

      Name : fname
Description: output file name

Returns    : TRUE upon success, FALSE otherwise

This function will create a unique file name in the specified directory path. Note that the output file is not actually created. The output file name is created minus the directory path. Do not end the directory path with a path separator. The directory path may be a null string (which will indicate the current directory) but not a null pointer.

The unique file name created will be in the form:

   11111111.tmp

Where 11111111 is a sequential number between one and 99,999,999

exist

Prototype  : int exist(char *fname)
Parameters :
      Name : fname
Description: input file name

Returns    : TRUE if the file exists, FALSE otherwise

This function will test for existence of a file. One of two methods are used to determine whether a file exists depending on the platform. Under all platforms except Windows 32-bit the access function is used to determine if the file exists. Under Windows 32-bit, an attempt is made to actually open the file.

numrecs

Prototype  : int numrecs(FILE *fi)
Parameters :
      Name : fi
Description: input file stream

Returns    : number of records/lines in the file, zero otherwise

This function will determine the number of lines/records in an ASCII file. Each line is assumed to be delimited by the appropriate line delimiter. The input file stream may be positioned to any part in the file as a rewind function call is made prior to counting.

get_nrec

Prototype  : void get_nrec(int recno, FILE *fi, char *buf)
Parameters :
      Name : recno
Description: record/line number

      Name : fi
Description: input file stream

      Name : buf
Description: output buffer

Read and get a specific record/line number from the input file stream. The line contents are placed into the output buffer upon success. The input file stream may be positioned to any part in the file as a rewind function call is made prior to counting.

get_rec

Prototype  : void get_rec(FILE *fi, char *buf)
Parameters :
      Name : fi
Description: input file stream

      Name : buf
Description: output buffer

Read the next record/line from the input file stream and place it into the output buffer. The line delimiter is stripped from the line.

zcreate

Prototype  : int zcreate(char *fname)
Parameters :
      Name : fname
Description: input file name

Returns    : TRUE upon success, FALSE otherwise

This function will create a zero byte file. If the file does not exist, it will be created. If the file does exist, it will be truncated to zero bytes. No overwrite protection is provided.

isdirectory

Prototype  : int isdirectory(char *path)
Parameters :
      Name : path
Description: directory path

Returns    : TRUE if a directory, FALSE otherwise

This function will determine whether the given directory path is actually a directory. The POSIX opendir system call is used for the test.

filecopy

Prototype  : int filecopy(char *src, char *dest)
Parameters :
      Name : src
Description: source path/name

      Name : dest
Description: destination path/name

Returns    : TRUE if the copy was successful, FALSE otherwise

This function will copy a file from the source path/name to the destination path/name. If the destination path/name exists, it will be overwritten without warning. A 32kb buffer is used to copy the file.

qrename

Prototype  : int qrename(char *src, char *dest)
Parameters :
      Name : src
Description: source path/name

      Name : dest
Description: destination path/name

Returns    : TRUE if the rename was successful, FALSE otherwise

Rename a file. A file may be renamed anywhere: same directory, different directory on same drive, different directory on different drive. Function works by first attempting the standard rename function. If that fails, the file is renamed by using the filecopy function and then deleting the source path/name. Currently, no check is made if the destination path/name exists. Since the filecopy function will overwrite the destination path/name, care should be exercised.

Goto Top | GPL Software Overview | GPL Library Overview
Future Lab Home | Contact Webmaster | Feedback

Copyright © 1999-2006 Future Lab, Last Updated Jun 30, 2006