Minor, rename blob to data on blob_from_file
This commit is contained in:
parent
fa090ed4d4
commit
7b4099f35f
|
@ -593,10 +593,10 @@ fail_without_close:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The following tries to read a file without knowing its size beforehand
|
// The following tries to read a file without knowing its size beforehand
|
||||||
// It's used for systems without mmap concept or to read from pipes
|
// It's used as a fallback for systems without mmap or to read from pipes
|
||||||
unsigned long len = 0, allocated = BUFSIZ * 16;
|
unsigned long len = 0, allocated = BUFSIZ * 16;
|
||||||
char *blob = (char *) malloc (allocated);
|
char *data = (char *) malloc (allocated);
|
||||||
if (unlikely (blob == nullptr)) return hb_blob_get_empty ();
|
if (unlikely (data == nullptr)) return hb_blob_get_empty ();
|
||||||
|
|
||||||
FILE *fp = fopen (file_name, "rb");
|
FILE *fp = fopen (file_name, "rb");
|
||||||
if (unlikely (fp == nullptr)) goto fread_fail_without_close;
|
if (unlikely (fp == nullptr)) goto fread_fail_without_close;
|
||||||
|
@ -609,12 +609,12 @@ fail_without_close:
|
||||||
// Don't allocate and go more than ~536MB, our mmap reader still
|
// Don't allocate and go more than ~536MB, our mmap reader still
|
||||||
// can cover files like that but lets limit our fallback reader
|
// can cover files like that but lets limit our fallback reader
|
||||||
if (unlikely (allocated > (2 << 28))) goto fread_fail;
|
if (unlikely (allocated > (2 << 28))) goto fread_fail;
|
||||||
char *new_blob = (char *) realloc (blob, allocated);
|
char *new_data = (char *) realloc (data, allocated);
|
||||||
if (unlikely (new_blob == nullptr)) goto fread_fail;
|
if (unlikely (new_data == nullptr)) goto fread_fail;
|
||||||
blob = new_blob;
|
data = new_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long addition = fread (blob + len, 1, allocated - len, fp);
|
unsigned long addition = fread (data + len, 1, allocated - len, fp);
|
||||||
|
|
||||||
int err = ferror (fp);
|
int err = ferror (fp);
|
||||||
if (unlikely (err == EINTR)) continue;
|
if (unlikely (err == EINTR)) continue;
|
||||||
|
@ -623,12 +623,12 @@ fail_without_close:
|
||||||
len += addition;
|
len += addition;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hb_blob_create (blob, len, HB_MEMORY_MODE_WRITABLE, blob,
|
return hb_blob_create (data, len, HB_MEMORY_MODE_WRITABLE, data,
|
||||||
(hb_destroy_func_t) free);
|
(hb_destroy_func_t) free);
|
||||||
|
|
||||||
fread_fail:
|
fread_fail:
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
fread_fail_without_close:
|
fread_fail_without_close:
|
||||||
free (blob);
|
free (data);
|
||||||
return hb_blob_get_empty ();
|
return hb_blob_get_empty ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue