don't use variable length array
This commit is contained in:
parent
de294b0784
commit
914c295177
|
@ -330,11 +330,17 @@ xfflush(xFILE *file)
|
||||||
PIC_INLINE size_t
|
PIC_INLINE size_t
|
||||||
xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
|
xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
|
||||||
{
|
{
|
||||||
|
char cbuf[256], *buf;
|
||||||
char *dst = (char *)ptr;
|
char *dst = (char *)ptr;
|
||||||
char buf[block];
|
|
||||||
size_t i, offset;
|
size_t i, offset;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
if (block <= 256) {
|
||||||
|
buf = cbuf;
|
||||||
|
} else {
|
||||||
|
buf = malloc(block);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < nitems; ++i) {
|
for (i = 0; i < nitems; ++i) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
if (file->ungot != -1 && block > 0) {
|
if (file->ungot != -1 && block > 0) {
|
||||||
|
@ -359,6 +365,10 @@ xfread(void *ptr, size_t block, size_t nitems, xFILE *file)
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
|
if (cbuf != buf) {
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue