mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
lib: Simplify tdb_fetch_int32()
With tdb_parse_record we don't need malloc/SAFE_FREE. The semantics are a bit different from tdb_parse_uint32: We just return -1 on error, but this could be overloaded with a valid -1 record value. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
7f0a87990e
commit
604c16453c
@ -132,20 +132,19 @@ void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval)
|
|||||||
Output is int32_t in native byte order.
|
Output is int32_t in native byte order.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int fetch_int32_parser(TDB_DATA key, TDB_DATA data, void *private_data)
|
||||||
|
{
|
||||||
|
if (data.dsize == sizeof(int32_t)) {
|
||||||
|
*((int32_t *)private_data) = PULL_LE_I32(data.dptr, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key)
|
static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key)
|
||||||
{
|
{
|
||||||
TDB_DATA data;
|
int v = -1;
|
||||||
int32_t ret;
|
tdb_parse_record(tdb, key, fetch_int32_parser, &v);
|
||||||
|
return v;
|
||||||
data = tdb_fetch(tdb, key);
|
|
||||||
if (!data.dptr || data.dsize != sizeof(int32_t)) {
|
|
||||||
SAFE_FREE(data.dptr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = IVAL(data.dptr,0);
|
|
||||||
SAFE_FREE(data.dptr);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user