2014年01月16日 星期四 10:52
UUID的全称是 universally unique identifier ,是一串挺长的数据,保证全宇宙唯一。APR的UUID模块提供了UUID的生成方法,代码示例如下:
#include <stdio.h> #include <apr.h> #include <apr_pools.h> #include <apr_errno.h> #include <apr_strings.h> #include <apr_uuid.h> void apr_err(const char *s, apr_status_t rv) { char buf[120]; fprintf(stderr, "%s: %s (%d)\n", s, apr_strerror(rv, buf, sizeof buf), rv); } int main(int argc,char **argv) { apr_initialize(); apr_pool_t *pool; apr_pool_create(&pool,NULL); apr_status_t st; apr_uuid_t uuid; apr_uuid_get(&uuid); char *uuidstr=apr_pcalloc(pool, APR_UUID_FORMATTED_LENGTH+1); apr_uuid_format(uuidstr,&uuid); printf("new uuid: %s\n",uuidstr); apr_uuid_t uuid2; apr_uuid_parse(&uuid2,uuidstr); printf("%d\n",memcmp(&uuid,&uuid2,sizeof(uuid))); apr_pool_destroy(pool); apr_terminate(); return 0; }
参考资料:
http://apr.apache.org/docs/apr-util/1.3/group___a_p_r___u_u_i_d.html
Zeuux © 2024
京ICP备05028076号