char* timestamp_to_string(const timestamp_t* time) {
struct tm t;
t.tm_hour = time->tm_hour; t.tm_mday = time->tm_mday; t.tm_min = time->tm_min; t.tm_mon = time->tm_mon; t.tm_sec = time->tm_sec; t.tm_wday = time->tm_wday; t.tm_yday = time->tm_yday; t.tm_year = time->tm_year;
#pragma warning(push) /* C4996 */ #pragma warning( disable : 4996 ) return asctime(&t);
#pragma warning(pop) /* C4996 */ } /**
* Compare two UUID's lexically * return
* -1 u1 is lexically before u2 * 0 u1 is equal to u2
* 1 u1 is lexically after u2
*/
int uuid_compare(const uuid_t *u1, const uuid_t *u2) {
int i;
#define CHECK_COMP(f1, f2) if ((f1) != (f2)) return ((f1) < (f2) ? -1 : 1);
CHECK_COMP(u1->data1, u2->data1); CHECK_COMP(u1->data2, u2->data2); CHECK_COMP(u1->data3, u2->data3);
for(i=0; i<8; i++)
CHECK_COMP(u1->data4[i], u1->data4[i]);
#undef CHECK_COMP
return 0; }
/**
* Compare two UUID's temporally * return
* -1 u1 is temporally before u2 * 0 u1 is equal to u2
* 1 u1 is temporally after u2 */
int uuid_compare_time(const uuid_t *u1, const uuid_t *u2) {
#define CHECK_COMP(f1, f2) if ((f1) != (f2)) return ((f1) < (f2) ? -1 : 1);
CHECK_COMP(u1->data1, u2->data1); CHECK_COMP(u1->data2, u2->data2); CHECK_COMP(u1->data3, u2->data3);
#undef CHECK_COMP
return 0; }
好了,到此,所有文件都列出来了,它们是:cdatatype.h、md5.h、uuid32.h、md5.c和uuid32.c。 最后是测试代码:
/* uuidgen.c
2007-09-15 Last created by cheungmine. All rights reserved by cheungmine.
C application */
#include
#include \#include \
int main() {
char *sign, *uid; uuid_t u, v, x; timestamp_t t;
sign = MD5_sign(\int)strlen(\
printf(\
uuid_create(&u);
uid = uuid_to_string(&u);
printf(\
uuid_create(&v);
uid = uuid_to_string(&v);
printf(\
printf(\
printf(%u));
uid = uuid_create_string();
printf(\
uuid_create_external(\ uid = uuid_to_string(&x);
printf(\
uuid_to_timestamp(&u, &t);
printf(\
return 0; }