mirror of
https://github.com/mon/2dxTools.git
synced 2024-11-27 23:40:49 +01:00
35 lines
815 B
C
35 lines
815 B
C
#include "shared.h"
|
|
#include <stdlib.h>
|
|
|
|
// TODO: buffering for speed
|
|
void transfer_file(FILE* in, FILE* out, size_t bytes) {
|
|
char byte;
|
|
for(size_t i = 0; i < bytes; i++) {
|
|
if(!fread(&byte, 1, 1, in)) {
|
|
printf("Could not read all bytes from input!\n");
|
|
exit(1);
|
|
}
|
|
fwrite(&byte, 1, 1, out);
|
|
}
|
|
}
|
|
|
|
// returns 0 if file is empty or noexistant, filesize otherwise
|
|
size_t file_size(const char* path) {
|
|
FILE* f = fopen(path, "rb");
|
|
if(!f)
|
|
return 0;
|
|
fseek(f, 0L, SEEK_END);
|
|
size_t size = ftell(f);
|
|
fclose(f);
|
|
return size;
|
|
}
|
|
|
|
// platform agnostic and proves we can read a file too
|
|
int file_exists(const char *path) {
|
|
FILE *file;
|
|
if ((file = fopen(path, "rb"))) {
|
|
fclose(file);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
} |