/*

  (c) 1990 S.Hawtin.
  Permission is granted to copy this file provided that:
   1) It is not used for commercial gain
   2) This notice is included in all copies
   3) Altered copies are marked as such

*/

/* A function to copy files */

#include <stdio.h>

int
copy(srcName,destName)
    char *srcName;
    char *destName;
   {/* Copy a file from source to dest */
    FILE *srcFp;
    FILE *destFp;
    char buffer[1024];
    int num;

    srcFp = fopen(srcName,"r");
    if(srcFp==NULL)
        return(-1);
    destFp = fopen(destName,"w");
    if(destFp==NULL)
       {fclose(srcFp);
        return(-1);
        }
    num = fread(buffer,sizeof(char),1024,srcFp);
    while(num > 0)
       {
        num = fwrite(buffer,sizeof(char),num,destFp);
        if(num > 0)
            num = fread(buffer,sizeof(char),1024,srcFp);
        }

    fclose(srcFp);
    fclose(destFp);

    return(num);
    }
