/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * COPYING NOTES * * test.c -- minimal test for I/O file library * * Copyright (C) 2002 Roberto A. Foglietta <robang@libero.it> * Copyright (C) 2002 GEA-Automotive <fogliettar@gea-automotive.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * REVISION NOTES: * released 16-10-2002 by Roberto A. Foglietta */ #ifdef AFTER_LIBIOFILE_INSTALLED #include <iofile.h> #else #include "iofile.h" #endif int main(int argc, char **argv) { FILE *fp; long len; unsigned char *buffer, ch; unsigned long lun; if(argc == 3) { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * filep = check_n_openfile ( name, mode ); * * this function return the pointer 'filep' to the file which 'name' was passed * as first argument opened in 'mode' (es.: "r+", "wt", etc.). In case of fatal * error 'filep' will be set to NULL. */ printf("\nTrying to open '%s' in '%s' mode\n", argv[1], argv[2]); fp = check_n_openfile(argv[1], argv[2]); printf("File pointer address is: 0x%lx\n", (unsigned long)fp); if(fp == NULL) return 1; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * lung = get_file_lenght ( filep ); * * this function return the lenght 'lung' of the file pointed by 'filep' passed * as first parameter, that point to opened file which you're interested in. */ printf("\nTrying to check '%s' file lenght\n", argv[1]); lun = get_file_lenght (fp); printf("File lenght is: %ld\n", lun); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * buffer = read_file_to_buffer (name, mode, &lun); * * this function try to access to the file specified by path in the first * parameter 'name' and check if it possibile open it in 'mode' (es.: "r+", * "rt", etc.), check the lenght and store it in 'lun', alloc the necessary * memory, open the file and read it into allocated buffer. If each of these * will succeded it will return the pointer to allocated buffer which contain * the file contenent otherwise it will return NULL. */ printf("\nTrying to read '%s' file\n", argv[1]); buffer = read_file_to_buffer (argv[1], argv[2], &len); printf("File pointer address is: 0x%lx\n", (unsigned long)fp); printf("File lenght is: %ld\n", len); if(fp == NULL || len <= 0) return 2; printf("Would you see the '%s' file contenent [s/N]?\n", argv[1]); scanf("%c", &ch); if(ch == 's' || ch == 'S') printf("%s", buffer); free(buffer); } else { printf("\nI/O FILE LIBRERY TEST\n"); printf("\ntest (filename) (mode)\n"); printf("\nes.: \"test test.c rt\"\n"); } return 0; }