Da ich etwas Zeit und Lust hatte, habe ich mal copy so ungefähr implementiert. Funktioniert für Text- und Binärdateien.
// all you need is stdio...
#include <stdio.h>
int myCopyFunction(char* szSource, char* szTarget) {
FILE *pSource, *pTarget;
if (!(pSource = fopen(szSource, "rb"))) {
fprintf(stderr, "Cannot open file \"%s\"\n", szSource);
return 1;
}
if (!(pTarget = fopen(szTarget, "wb"))) {
fprintf(stderr, "Cannot open file \"%s\"\n", szTarget);
return 1;
}
#define LINELEN 180
#define BLOCKTYPE char
BLOCKTYPE szLine[LINELEN];
int nBytesRead, nErrorValue = 0;
do {
nBytesRead = fread(szLine, sizeof(BLOCKTYPE), LINELEN, pSource);
if (nBytesRead != fwrite(szLine, sizeof(BLOCKTYPE), nBytesRead, pTarget)) {
// if an error occured
nErrorValue = 1;
break;
}
} while(nBytesRead == LINELEN);
if (ferror(pSource)) {
nErrorValue = 1;
}
fclose(pSource);
fclose(pTarget);
return nErrorValue;
}
int main (int argc, char* argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s SOURCE TARGET\n", argv[0]);
fprintf(stderr, " copies SOURCE to TARGET\n");
return 1;
}
return myCopyFunction(argv[1], argv[2]);
}