[klibc] Re: klibc-0.72 released
Andi Kuebler
andi.kuebler@t-online.de
Sat, 11 Jan 2003 21:58:33 +0100 (CET)
On Wed, 8 Jan 2003, Rusty Russell wrote:
> [...]
>
> /* Read in the entire file. */
> static void *read_in(const char *entname, unsigned long *len, int noexistok)
> {
> char *ret;
> unsigned long done = 0;
> int r, fd;
> struct stat statbuf;
> char filename[strlen(MODDIR) + 1 + strlen(entname) + 1];
>
> sprintf(filename, "%s/%s", MODDIR, entname);
> fd = open(filename, O_RDONLY);
> if (fd < 0) {
> if (errno == ENOENT && noexistok) {
> *len = 0;
> return strdup("");
> }
> fatal("Failed to open %s: %s\n", filename, strerror(errno));
> }
> fstat(fd, &statbuf);
> *len = statbuf.st_size;
> ret = malloc(*len + 1);
shouldn't we test malloc's return value?
Andi