006
19.12.2004, 21:43 Uhr
Pablo
Supertux (Operator)
|
Ich habe einmal sowas geschrieben, was du willst, ich hab den Code gefunden:
C++: |
#define MAX_LENGTH 4096
#include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <malloc.h>
static void fehl_meldung(const char *fmt, va_list az) { char puffer[MAX_LENGTH]; vsprintf(puffer, fmt, az); fprintf(stderr, "%s\n", puffer); }
/*---------------------- global error routine -----------------------*/ void error_call(const char *fmt, ...) { va_list az;
va_start(az, fmt); fehl_meldung(fmt,az);
va_end(az); }
...
int copyfile(const char* source, const char* destiny) { FILE* src, *dty; unsigned int read=0; char buffer[MAX_LENGTH];
if((src=fopen(source, "rb")) == NULL) return -1; if((dty=fopen(destiny, "wb")) == NULL) { fclose(src); return -2; }
while( (read = fread(buffer,1,MAX_LENGTH, src)) > 0 ) { if(read != fwrite(buffer, 1, read, dty)) { fclose(dty); fclose(src); error_call("Not all data could be copied into %s. Proc. aborted.", destiny); return -3; } }
fclose(dty); fclose(src); return 0; }
|
das ist der interessante Teil, der Code ist insgesamt 8.8 KB groß. -- A! Elbereth Gilthoniel! silivren penna míriel o menel aglar elenath, Gilthoniel, A! Elbereth! |