[内部実装]
#include "kclib1.h"
#include <stdio.h>
#include <string.h>
int KSizPtr_readFile(KSizPtr *w, const char *path, const char *mod, int flg)
{
KSizPtr sp, *v = &sp;
int i;
FILE *fp = fopen(path, mod);
if (fp == 0) {
if (path == 0)
path = "(NULL)";
if ((flg & 1) != 0)
kerrorExit("KSizPtr_readFile: fopen error: '%s'", path);
return -1;
}
if ((flg & 4) != 0)
v = w;
KSizPtr_init(v, 256 * 1024);
for (;;) {
if (v->s >= v->s1)
KSizPtr_expand2(v);
i = fread(v->p + v->s, 1, v->s1 - v->s, fp);
if (i == 0) break;
v->s += i;
}
fclose(fp);
i = v->s;
if ((flg & 2) != 0) {
static char z16[16];
KSizPtr_addBytes(v, 16, z16);
}
if (w != v) {
KSizPtr_addBytes(w, v->s, v->p);
KSizPtr_free(v);
}
return i;
}