1 /* ----------------------------------------------------------------------- *
3 * Copyright 2005 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * Read the contents of a data file into a malloc'd buffer
28 int loadfile(const char *filename
, void **ptr
, size_t *len
)
36 fd
= open(filename
, O_RDONLY
);
50 xlen
= (st
.st_size
+ LOADFILE_ZERO_PAD
-1) & ~(LOADFILE_ZERO_PAD
-1);
52 *ptr
= data
= malloc(xlen
);
56 if ( (off_t
)fread(data
, 1, st
.st_size
, f
) != st
.st_size
)
59 memset((char *)data
+ st
.st_size
, 0, xlen
-st
.st_size
);