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 but not a null pointer.

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. This function is available for the Unix platform only. The Unix access function is used to test. Note that this test can be fooled by an executable program by the same name.

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. This function is an exception to the other file i/o functions in this module because it does not use stream i/o. The open, read, write and close functions are used in this function.

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 Library Overview | GPL Library
Future Lab Home | Contact Webmaster | Feedback

Copyright © 1999 Future Lab Inc., Last Updated May 7, 1999