mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-09 01:21:05 +00:00
Update sdb from git
This commit is contained in:
parent
3a262ba5d7
commit
582863189d
@ -1,7 +1,7 @@
|
||||
#ifndef SDB_H
|
||||
#define SDB_H
|
||||
|
||||
#if !defined(O_BINARY) && !defined(_MSC_VER)
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
@ -29,7 +29,7 @@ extern "C" {
|
||||
#define SZT_ADD_OVFCHK(x, y) ((SIZE_MAX - (x)) <= (y))
|
||||
#endif
|
||||
|
||||
#if __SDB_WINDOWS__ && !__CYGWIN__ && !_MSC_VER
|
||||
#if __SDB_WINDOWS__ && !__CYGWIN__
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
@ -92,6 +92,7 @@ typedef struct sdb_t {
|
||||
SdbList *hooks;
|
||||
SdbKv tmpkv;
|
||||
ut32 depth;
|
||||
bool timestamped;
|
||||
} Sdb;
|
||||
|
||||
typedef struct sdb_ns_t {
|
||||
|
@ -6,10 +6,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef eprintf
|
||||
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define eprintf(x,y...) fprintf(stderr,x,##y)
|
||||
|
||||
#ifndef SDB_API
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
@ -31,7 +30,7 @@
|
||||
#define __MINGW__ 1
|
||||
#endif
|
||||
|
||||
#if __WIN32__ || __MINGW__ || __WINDOWS__ || defined(_MSC_VER)
|
||||
#if __WIN32__ || __MINGW__ || __WINDOWS__ || _MSC_VER
|
||||
#define __SDB_WINDOWS__ 1
|
||||
#include <windows.h>
|
||||
#define DIRSEP '\\'
|
||||
@ -41,10 +40,8 @@
|
||||
#define DIRSEP '/'
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#define ULLFMT "ll"
|
||||
|
||||
#if __SDB_WINDOWS__ && !__CYGWIN__
|
||||
#define HAVE_MMAN 0
|
||||
#else
|
||||
@ -55,6 +52,7 @@
|
||||
#define USE_MMAN HAVE_MMAN
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef UNUSED
|
||||
# define UNUSED
|
||||
|
12
shlr/sdb/Jamroot
Normal file
12
shlr/sdb/Jamroot
Normal file
@ -0,0 +1,12 @@
|
||||
CFILES = src/buffer.c src/ht.c src/ls.c src/query.c src/num.c ;
|
||||
CFILES += src/cdb.c src/json.c src/sdb.c src/util.c src/base64.c ;
|
||||
CFILES += src/cdb_make.c src/lock.c src/ns.c src/array.c src/disk.c ;
|
||||
|
||||
#CFILES += src/json/api.c src/json/path.c src/json/rangstr.c ;
|
||||
#CFILES += src/json/js0n.c ;
|
||||
|
||||
lib sdb : $(CFILES) : <link>static <include>. ;
|
||||
|
||||
exe sdb : $(CFILES) src/main.c : <include>. ;
|
||||
|
||||
ret = [ SHELL "echo '#define SDB_VERSION \"0.9.8\"' > src/sdb_version.h" ] ;
|
@ -77,7 +77,7 @@ INCFILES+=src/ls.h src/cdb_make.h src/buffer.h src/config.h
|
||||
install: pkgconfig install-dirs
|
||||
$(INSTALL_MAN) src/sdb.1 ${DESTDIR}${MANDIR}
|
||||
$(INSTALL_LIB) src/libsdb.${EXT_SO} ${DESTDIR}${LIBDIR}
|
||||
$(INSTALL_DATA) src/libsdb.$(EXT_AR) ${DESTDIR}${LIBDIR}
|
||||
$(INSTALL_DATA) src/libsdb.a ${DESTDIR}${LIBDIR}
|
||||
-if [ "$(EXT_SO)" != "$(SOVER)" ]; then \
|
||||
cd ${DESTDIR}${LIBDIR} ; \
|
||||
mv libsdb.$(EXT_SO) libsdb.$(SOVER) ; \
|
||||
@ -87,7 +87,7 @@ install: pkgconfig install-dirs
|
||||
$(INSTALL_DATA) $(INCFILES) ${DESTDIR}${INCDIR}/sdb
|
||||
$(INSTALL_PROGRAM) src/sdb ${DESTDIR}${BINDIR}
|
||||
ifeq ($(BUILD_MEMCACHE),1)
|
||||
$(INSTALL_DATA) memcache/libmcsdb.$(EXT_AR) ${DESTDIR}${LIBDIR}
|
||||
$(INSTALL_DATA) memcache/libmcsdb.a ${DESTDIR}${LIBDIR}
|
||||
$(INSTALL_DATA) memcache/mcsdb.h ${DESTDIR}${INCDIR}/sdb
|
||||
$(INSTALL_PROGRAM) memcache/mcsdbd ${DESTDIR}${BINDIR}
|
||||
$(INSTALL_PROGRAM) memcache/mcsdbc ${DESTDIR}${BINDIR}
|
||||
@ -108,7 +108,7 @@ deinstall uninstall:
|
||||
rm -f ${DESTDIR}${BINDIR}/mcsdbc
|
||||
rm -f ${DESTDIR}${BINDIR}/mcsdbd
|
||||
rm -f ${DESTDIR}${LIBDIR}/libsdb.*
|
||||
rm -f ${DESTDIR}${LIBDIR}/libmcsdb.$(EXT_AR)
|
||||
rm -f ${DESTDIR}${LIBDIR}/libmcsdb.a
|
||||
rm -f ${DESTDIR}${LIBDIR}/pkgconfig/sdb.pc
|
||||
rm -f ${DESTDIR}${LIBDIR}/pkgconfig/mcsdb.pc
|
||||
rm -f ${DESTDIR}${MANDIR}/sdb.1
|
||||
|
@ -54,7 +54,7 @@ endif
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -o ${BIN} main.o ${OBJ}
|
||||
|
||||
mrproper clean:
|
||||
rm -rf ${OBJ} ${SOBJ} main.o libsdb.$(EXT_AR) a.out ${BIN} sdb.dSYM
|
||||
rm -rf ${OBJ} ${SOBJ} main.o libsdb.a a.out ${BIN} sdb.dSYM
|
||||
rm -rf *.d *._d json/*.d json/*._d *.sdb *.db *.${EXT_SO} *.${EXT_SO}.*
|
||||
|
||||
# rules #
|
||||
|
@ -101,7 +101,7 @@ bool cdb_read(struct cdb *c, char *buf, ut32 len, ut32 pos) {
|
||||
return false;
|
||||
}
|
||||
while (len > 0) {
|
||||
ut32 r = read (c->fd, buf, len);
|
||||
ssize_t r = read (c->fd, buf, len);
|
||||
if (r < 1 || (ut32) r != len) {
|
||||
return false;
|
||||
}
|
||||
|
@ -96,11 +96,7 @@ SDB_API bool sdb_journal_log(Sdb *s, const char *key, const char *val) {
|
||||
|
||||
SDB_API bool sdb_journal_clear(Sdb *s) {
|
||||
if (s->journal != -1) {
|
||||
#ifdef _MSC_VER
|
||||
return !_chsize (s->journal, 0);
|
||||
#else
|
||||
return !ftruncate (s->journal, 0);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -5,12 +5,6 @@
|
||||
|
||||
#include "rangstr.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma message ("TODO: json not implemented for this platform")
|
||||
int js0n(const ut8 *js, RangstrType len, RangstrType *out) {
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
|
||||
#pragma GCC diagnostic push
|
||||
#endif
|
||||
@ -151,4 +145,3 @@ l_utf_continue:
|
||||
go = gostring;
|
||||
goto l_loop;
|
||||
}
|
||||
#endif
|
||||
|
@ -5,10 +5,6 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "sdb.h"
|
||||
#ifdef _MSC_VER
|
||||
#include <process.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
SDB_API const char *sdb_lock_file(const char *f) {
|
||||
static char buf[128];
|
||||
@ -54,7 +50,7 @@ SDB_API int sdb_lock_wait(const char *s) {
|
||||
// wait forever here?
|
||||
while (!sdb_lock (s)) {
|
||||
// TODO: if waiting too much return 0
|
||||
#if __SDB_WINDOWS__ || _MSC_VER
|
||||
#if __SDB_WINDOWS__
|
||||
Sleep (500); // hack
|
||||
#else
|
||||
// TODO use lockf() here .. flock is not much useful (fd, LOCK_EX);
|
||||
|
@ -69,12 +69,12 @@ SDB_API Sdb* sdb_new(const char *path, const char *name, int lock) {
|
||||
break;
|
||||
}
|
||||
if (sdb_open (s, s->dir) == -1) {
|
||||
s->last = sdb_now ();
|
||||
s->last = s->timestamped? sdb_now (): 0LL;
|
||||
// TODO: must fail if we cant open for write in sync
|
||||
}
|
||||
s->name = strdup (name);
|
||||
} else {
|
||||
s->last = sdb_now ();
|
||||
s->last = s->timestamped? sdb_now (): 0LL;
|
||||
s->fd = -1;
|
||||
}
|
||||
s->journal = -1;
|
||||
@ -214,7 +214,7 @@ SDB_API const char *sdb_const_get_len(Sdb* s, const char *key, int *vlen, ut32 *
|
||||
if (!kv->value || !*kv->value) {
|
||||
return NULL;
|
||||
}
|
||||
if (kv->expire) {
|
||||
if (s->timestamped && kv->expire) {
|
||||
if (!now) {
|
||||
now = sdb_now ();
|
||||
}
|
||||
@ -928,6 +928,7 @@ SDB_API bool sdb_expire_set(Sdb* s, const char *key, ut64 expire, ut32 cas) {
|
||||
ut32 pos, len;
|
||||
SdbKv *kv;
|
||||
bool found;
|
||||
s->timestamped = true;
|
||||
if (!key) {
|
||||
s->expire = parse_expire (expire);
|
||||
return true;
|
||||
@ -1015,7 +1016,7 @@ SDB_API int sdb_hook_call(Sdb *s, const char *k, const char *v) {
|
||||
SdbListIter *iter;
|
||||
SdbHook hook;
|
||||
int i = 0;
|
||||
if (s->last) {
|
||||
if (s->timestamped && s->last) {
|
||||
s->last = sdb_now ();
|
||||
}
|
||||
ls_foreach (s->hooks, iter, hook) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef SDB_H
|
||||
#define SDB_H
|
||||
|
||||
#if !defined(O_BINARY) && !defined(_MSC_VER)
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
@ -36,10 +36,8 @@ extern "C" {
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <io.h>
|
||||
#ifndef _MSC_VER
|
||||
extern __attribute__((dllimport)) void *__cdecl _aligned_malloc(size_t, size_t);
|
||||
extern char *strdup (const char *);
|
||||
#endif
|
||||
#undef r_offsetof
|
||||
#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member)
|
||||
//#define SDB_MODE 0
|
||||
@ -94,6 +92,7 @@ typedef struct sdb_t {
|
||||
SdbList *hooks;
|
||||
SdbKv tmpkv;
|
||||
ut32 depth;
|
||||
bool timestamped;
|
||||
} Sdb;
|
||||
|
||||
typedef struct sdb_ns_t {
|
||||
|
@ -6,10 +6,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef eprintf
|
||||
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define eprintf(x,y...) fprintf(stderr,x,##y)
|
||||
|
||||
#ifndef SDB_API
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
@ -43,7 +42,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#define ULLFMT "ll"
|
||||
#if defined(_MSC_VER) || (__SDB_WINDOWS__ && !__CYGWIN__)
|
||||
#if __SDB_WINDOWS__ && !__CYGWIN__
|
||||
#define HAVE_MMAN 0
|
||||
#else
|
||||
#define HAVE_MMAN 1
|
||||
@ -54,6 +53,7 @@
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef UNUSED
|
||||
# define UNUSED
|
||||
# ifdef __GNUC__
|
||||
@ -97,11 +97,7 @@
|
||||
#include "config.h"
|
||||
|
||||
static inline int seek_set(int fd, off_t pos) {
|
||||
#ifdef _MSC_VER
|
||||
return ((fd == -1) || (_lseek (fd, pos, SEEK_SET) == -1))? 0:1;
|
||||
#else
|
||||
return ((fd == -1) || (lseek (fd, (off_t) pos, SEEK_SET) == -1))? 0:1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void ut32_pack(char s[4], ut32 u) {
|
||||
|
@ -6,37 +6,9 @@
|
||||
|
||||
#if USE_MONOTONIC_CLOCK
|
||||
#include <time.h>
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#pragma message ("gettimeofday: Windows support is ugly here")
|
||||
#include <windows.h>
|
||||
int gettimeofday (struct timeval* p, void* tz) {
|
||||
ULARGE_INTEGER ul; // As specified on MSDN.
|
||||
FILETIME ft;
|
||||
|
||||
// Returns a 64-bit value representing the number of
|
||||
// 100-nanosecond intervals since January 1, 1601 (UTC).
|
||||
GetSystemTimeAsFileTime (&ft);
|
||||
|
||||
// Fill ULARGE_INTEGER low and high parts.
|
||||
ul.LowPart = ft.dwLowDateTime;
|
||||
ul.HighPart = ft.dwHighDateTime;
|
||||
// Convert to microseconds.
|
||||
ul.QuadPart /= 10ULL;
|
||||
// Remove Windows to UNIX Epoch delta.
|
||||
ul.QuadPart -= 11644473600000000ULL;
|
||||
// Modulo to retrieve the microseconds.
|
||||
p->tv_usec = (long)(ul.QuadPart % 1000000LL);
|
||||
// Divide to retrieve the seconds.
|
||||
p->tv_sec = (long)(ul.QuadPart / 1000000LL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SDB_API ut32 sdb_hash_len(const char *s, ut32 *len) {
|
||||
ut32 h = CDB_HASHSTART;
|
||||
@ -242,7 +214,7 @@ SDB_API const char *sdb_const_anext(const char *str, const char **next) {
|
||||
}
|
||||
|
||||
SDB_API ut64 sdb_now () {
|
||||
#if USE_MONOTONIC_CLOCK
|
||||
#if USE_MONOTINIC_CLOCK
|
||||
struct timespec ts;
|
||||
if (!clock_gettime (CLOCK_MONOTONIC, &ts)) {
|
||||
return ts.tv_sec;
|
||||
|
Loading…
x
Reference in New Issue
Block a user