internal.o: internal.c
$(CC) $(CFLAGS) -Wall -fPIC -c -o $@ $+
+uuidgen2: libpduuid.a uuidgen2.o
+ $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen2.o -lpduuid $(LDFLAGS)
+
uuidgen: libpduuid.a uuidgen.o
$(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
static uint64_t current_time(void) {
uint64_t now;
struct timeval tv;
+ static int seq = 0;
/* TODO is this BSD specific? */
gettimeofday(&tv, 0);
- now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL) + GREGORIAN;
+ now = (tv.tv_sec * 10000000ULL + tv.tv_usec * 10ULL + seq++ % 10) + GREGORIAN;
return now;
}
}
static int read_state(struct pd_uuid_state *s) {
+ uint64_t node;
+
s->available = 0;
s->node = 0LL;
s->clock_sequence = 0;
s->timestamp = 0LL;
+ node = current_node(s);
+
+ if (!s->available || s->node != node) {
+ s->clock_sequence = random_clock_sequence(s);
+ }
+
return 0;
}
return i;
}
+int pd_uuid_init(struct pd_uuid_state *s, int flags) {
+ if (!s) return 0;
+
+ s->get_lock = obtain_global_lock;
+ s->release_lock = release_global_lock;
+ s->lock_data = 0;
+
+ if (flags & 0x1) {
+ s->read_state = 0;
+ s->save_state = 0;
+ s->node = current_node(s);
+ } else {
+ s->read_state = read_state;
+ s->save_state = 0;
+ }
+
+ s->random_bytes = get_bytes;
+ s->rng_state = 0;
+
+ s->available = 0;
+
+ return 1;
+}
+
int pd_uuid_init_state(struct pd_uuid_state *s) {
if (!s) return 0;
int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid) {
struct pd_uuid_state ls;
uint64_t now;
- uint64_t node;
int err;
if (!s) {
}
now = current_time();
- node = current_node(s);
-
- if (!s->available || s->node != node) {
- s->clock_sequence = random_clock_sequence(s);
- }
-
- s->node = node;
if (s->available && s->timestamp > now) {
s->clock_sequence++;
typedef struct pd_uuid pd_uuid_t;
int pd_uuid_init_state(struct pd_uuid_state *s);
+int pd_uuid_init(struct pd_uuid_state *s, int f);
int pd_uuid_make_v1(struct pd_uuid_state *s, pd_uuid_t *uuid);
int pd_uuid_make_v1mc(struct pd_uuid_state *s, pd_uuid_t *uuid);
int pd_uuid_make_v4(struct pd_uuid_state *s, pd_uuid_t *uuid);
}
}
+#if 0
static int strbytes(char *s, unsigned char *d) {
unsigned int byte;
int i = 0;
}
return i;
}
+#endif
int main(int ac, char *av[]) {
unsigned char tmp[20];
char want[64];
char have[64];
- static const struct {
+ static struct {
char *msg;
int repeat;
unsigned char hash[20];
{ "0123456701234567012345670123456701234567012345670123456701234567", 10,
{0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52},
},
- { NULL, { 0 } }
+ { NULL, 0, { 0 } }
};
plan(8);
int main(int ac, char *av[]) {
pd_uuid_t uuid, copy;
struct pd_uuid_state s;
+ pd_uuid_t idset[10];
+ int i;
char fmt[37];
unsigned char hash[40];
srandom(time(0));
#endif
- plan(15);
+ plan(24);
pd_uuid_init_state(0);
pd_uuid_make_v1mc(0, &uuid);
ufmt(©, fmt);
diag("v1b: %s", fmt);
+ pd_uuid_init(&s, 0x1);
+ for (i=0;i<10;i++) {
+ pd_uuid_make_v1(&s, &idset[i]);
+ }
+ for (i=0;i<9;i++) {
+ ok(pd_uuid_cmp(&idset[i], &idset[i+1]), "id set %d != %d", i, i+1);
+ pd_uuid_make_v1(&s, &idset[i]);
+ }
+
return 0;
}