home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / doom_i / program / tcpsrv12.exe / TCPSRV12.TAR / fileio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-27  |  1.3 KB  |  69 lines

  1. /* fileio.c */
  2. /*
  3.  
  4.  * Copyright 1994 A.Oliver De Guzman
  5.  * All rights reserved
  6.  
  7.  *   Permission is granted to any individual to copy, use, and/or
  8.  * distribute this software provided that the distribution retains this
  9.  * entire copyright notice. No part of this software may be used and/or
  10.  * sold for profit or used with any commercial product.
  11.  
  12.  * DISCLAIMER:
  13.  *   This software comes with NO WARRANTIES of any kind. In no event
  14.  * will the author be liable for any financial, physical, moral, and/or
  15.  * mental damages incurred directly or indirectly by the use or intent
  16.  * to use of this software.
  17.  
  18.  */
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22.  
  23. int writefile(fname, buff, n)
  24. char *fname;
  25. char *buff;
  26. int n;
  27. {
  28.     FILE *fp;
  29.     int nb, where = 0;
  30.  
  31.     if (!(fp = fopen(fname, "w"))) return(-1);
  32.  
  33.     do{
  34.         if ((nb=fwrite(buff+where, sizeof(char), n-where, fp)) < 0){
  35.             perror("Write_File: write failed");
  36.             return(-1);
  37.         }
  38.         where += nb;
  39.     } while(n-where > 0 && nb > 0);
  40.  
  41.     fclose(fp);
  42.     return(where);
  43. }
  44.  
  45.  
  46. int readfile(fname, buff, n)
  47. char *fname;
  48. char *buff;
  49. int n;
  50. {
  51.     FILE *fp;
  52.     int nb, where = 0;
  53.  
  54.     if (!(fp = fopen(fname, "r"))) return(-1);
  55.  
  56.     do{
  57.         if ((nb=fread(buff+where, sizeof(char), n-where, fp)) < 0){
  58.             perror("Read_File: read failed");
  59.             return(-1);
  60.         }
  61.         where += nb;
  62.     } while(n-where > 0 && nb > 0);
  63.  
  64.     buff[where] = '\0';
  65.     fclose(fp);
  66.     return(where);
  67. }
  68.  
  69.