Remove assert, add _ent_fail

This commit is contained in:
Jōshin 2019-01-02 15:36:02 -08:00
parent 8ce0600e00
commit 1f0e431259
2 changed files with 14 additions and 8 deletions

View File

@ -1,4 +1,4 @@
project('libent', 'c', version: '0.1.1', license: 'MIT') project('libent', 'c', version: '0.1.2', license: 'MIT')
inc = include_directories('include') inc = include_directories('include')

View File

@ -14,7 +14,6 @@
} }
#elif defined(ENT_IMPL) #elif defined(ENT_IMPL)
# include <assert.h>
# include <errno.h> # include <errno.h>
# if defined(ENT_GETRANDOM) # if defined(ENT_GETRANDOM)
# define _GNU_SOURCE # define _GNU_SOURCE
@ -35,19 +34,26 @@
# define ENT_FINI() (void) fclose(f) # define ENT_FINI() (void) fclose(f)
# endif # endif
static int
_ent_fail()
{
errno = EIO;
return -1;
}
int int
ent_getentropy(void* buf, size_t len) ent_getentropy(void* buf, size_t len)
{ {
int r;
ENT_DEFS; ENT_DEFS;
assert(len <= 256); if (len > 256)
return _ent_fail();
ENT_INIT(); ENT_INIT();
if (len != ENT_READ(buf, len)) { r = ENT_READ(buf, len);
ENT_FINI();
errno = EIO;
return -1;
}
ENT_FINI(); ENT_FINI();
if (r != len)
return _ent_fail();
return 0; return 0;
} }