mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
Added int32 versions of the endian-dependent code.
Jeremy.
(This used to be commit d57fb9a8c2
)
This commit is contained in:
parent
eca00cab66
commit
b6f4f3465f
@ -54,6 +54,7 @@ void tdb_unlock_bystring(TDB_CONTEXT *tdb, char *keyval)
|
||||
|
||||
/****************************************************************************
|
||||
Fetch a value by a arbitrary blob key, return -1 if not found.
|
||||
JRA. DEPRECATED ! Use tdb_fetch_int32_byblob instead.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_fetch_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len)
|
||||
@ -68,12 +69,13 @@ int tdb_fetch_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len)
|
||||
return -1;
|
||||
|
||||
memcpy(&ret, data.dptr, sizeof(int));
|
||||
free(data.dptr);
|
||||
SAFE_FREE(data.dptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Fetch a value by string key, return -1 if not found.
|
||||
JRA. DEPRECATED ! Use tdb_fetch_int32 instead.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_fetch_int(TDB_CONTEXT *tdb, char *keystr)
|
||||
@ -83,6 +85,7 @@ int tdb_fetch_int(TDB_CONTEXT *tdb, char *keystr)
|
||||
|
||||
/****************************************************************************
|
||||
Store a value by an arbitary blob key, return 0 on success, -1 on failure.
|
||||
JRA. DEPRECATED ! Use tdb_store_int32_byblob instead.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v)
|
||||
@ -99,6 +102,7 @@ int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v)
|
||||
|
||||
/****************************************************************************
|
||||
Store a value by string key, return 0 on success, -1 on failure.
|
||||
JRA. DEPRECATED ! Use tdb_store_int32 instead.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v)
|
||||
@ -106,6 +110,66 @@ int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v)
|
||||
return tdb_store_int_byblob(tdb, keystr, strlen(keystr) + 1, v);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Fetch a int32 value by a arbitrary blob key, return -1 if not found.
|
||||
Output is int32 in native byte order.
|
||||
****************************************************************************/
|
||||
|
||||
int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len)
|
||||
{
|
||||
TDB_DATA key, data;
|
||||
int32 ret;
|
||||
|
||||
key.dptr = keyval;
|
||||
key.dsize = len;
|
||||
data = tdb_fetch(tdb, key);
|
||||
if (!data.dptr || data.dsize != sizeof(int32))
|
||||
return -1;
|
||||
|
||||
ret = IVAL(data.dptr,0);
|
||||
SAFE_FREE(data.dptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Fetch a int32 value by string key, return -1 if not found.
|
||||
Output is int32 in native byte order.
|
||||
****************************************************************************/
|
||||
|
||||
int32 tdb_fetch_int32(TDB_CONTEXT *tdb, char *keystr)
|
||||
{
|
||||
return tdb_fetch_int32_byblob(tdb, keystr, strlen(keystr) + 1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Store a int32 value by an arbitary blob key, return 0 on success, -1 on failure.
|
||||
Input is int32 in native byte order. Output in tdb is in little-endian.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_store_int32_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int32 v)
|
||||
{
|
||||
TDB_DATA key, data;
|
||||
int32 v_store;
|
||||
|
||||
key.dptr = keystr;
|
||||
key.dsize = len;
|
||||
SIVAL(&v_store,0,v);
|
||||
data.dptr = (void *)&v_store;
|
||||
data.dsize = sizeof(int32);
|
||||
|
||||
return tdb_store(tdb, key, data, TDB_REPLACE);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Store a int32 value by string key, return 0 on success, -1 on failure.
|
||||
Input is int32 in native byte order. Output in tdb is in little-endian.
|
||||
****************************************************************************/
|
||||
|
||||
int tdb_store_int32(TDB_CONTEXT *tdb, char *keystr, int32 v)
|
||||
{
|
||||
return tdb_store_int32_byblob(tdb, keystr, strlen(keystr) + 1, v);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Store a buffer by a null terminated string key. Return 0 on success, -1
|
||||
on failure.
|
||||
@ -374,7 +438,7 @@ static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...)
|
||||
return;
|
||||
|
||||
DEBUG(level, ("tdb(%s): %s", tdb->name, ptr));
|
||||
free(ptr);
|
||||
SAFE_FREE(ptr);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user