Linux under Installation using Libuuid (uuid-generate)

Source: Internet
Author: User
Tags uuid

Linux under Installation using Libuuid (uuid-generate)
    • Linux under Installation using Libuuid (uuid-generate)
      • Introduction to UUID
      • Installing the Libuuid Library
      • Write a program try it
        • Code
        • Compile run
Introduction to UUID

The UUID meaning is 通用唯一识别码 (universally Unique Identifier), which is a standard for software construction and is also used by the Open Software Foundation, OSF, to organize applications in a distributed computing environment ( Distributed Computing Environment, DCE) is part of the field.

A UUID is a number generated on a machine that is guaranteed to be for all machines in the same time and space 唯一 . Typically, the platform provides the generated APIs. According to the standards established by the Open Software Foundation (OSF), the use of 以太网卡地址 , 纳秒级时间 芯片ID码 and many possible numbers
The UUID is composed of the following parts:

    1. The current date and time, the first part of the UUID is related to time, and if you generate a UUID after a few seconds, the first part is different and the rest is the same.
    2. Clock sequence.
    3. Globally unique IEEE machine identification number, if there is a network card, from the network card MAC address obtained, no network card is obtained in other ways.

The only drawback to the UUID is that the resulting string will be longer. The most common use of the standard for UUID is 微软的GUID (Globals Unique Identifiers). In ColdFusion, the UUID can be easily generated with a function in the CreateUUID() form of: xxxxxxxx-xxxx- xxxx-xxxxxxxxxxxxxxxx(8-4-4-16) , each of which x is 0-9 a-f a hexadecimal number within the range. The standard UUID format is:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12)

Generate UUID libuuid The functions you can use under uuid-generate Linux

Installation libuuidLibrary

libuuidis a cross-platform open-source uuid operation Library. General machine on the default is not, first installed.

can also download the source code to install, http://nchc.dl.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz

After the installation can be used man uuid_generate to see how to use
Here, let's talk about uuid_t this type. You can find uuid.h this header file with a line inside it.typedef unsigned char uuid_t[16];

#include <uuid.h>    voidout);     void  out );     void  out );     int out);

There are some other functions that are listed here as well. It is not much to explain the meaning of these functions by looking at the function names. Do not understand the place to find manpages .

#include <uuid.h>//comparison of two UUID    intUuid_compare (uuid_t uu1, uuid_t uu2)//copy src to DST    voiduuid_copy (uuid_t DST, uuid_t src); //Clear UU content (clear 0)    voiduuid_clear (uuid_t uu); //to interpret if UU is null    intuuid_is_null (uuid_t uu); //parse in pointed string form content to UU    intUuid_parse (Char*inch, uuid_t UU); //Parse UU content into a string and save to an out array    voidUuid_unparse (uuid_t UU,Char* out); voidUuid_unparse_upper (uuid_t UU,Char* out); voidUuid_unparse_lower (uuid_t UU,Char* out); //resolves the time portion of the time-based UU that was createdtime_t uuid_time (uuid_t uu,structTimeval *RET_TV)

Write a program try the code
#include <stdio.h>#include<uuid/uuid.h>//gcc uuid.c-luuid-o uuidintMain () {intI,n; uuid_t uu[4]; Charbuf[1024x768]; structTimeval TV; //1.Uuid_generate (uu[0]); //2.Uuid_generate_random (uu[1]); //3.Uuid_generate_time (uu[2]); //4.n = Uuid_generate_time_safe (uu[3]); printf ("n =%d\n", N);  for(i=0;i<4;++i)        {Uuid_unparse (UU[I],BUF); printf ("uu[%d]\t\t%s\n", I,BUF); } uuid_time (uu[2],&TV); printf ("TV S:%LX u:%lx\n", tv.tv_sec,tv.tv_usec); return 0;}

Compile run
[Email protected]:~$ gcc uuid.c  -luuid[email protected]-pc:~$./a. Out0  uu[0]       0867a44e-b481-4fde-9b3c-1767b60702b6uu[1]       3f39e123-288b-4cf1-adf2-77fb763530dfuu[2]       b071a71e-261a-11e5-8513-  28d24473abc3uu[3]       b071a71f-261a-11e5-8513-28d24473abc3tv s:559e3b19  U:90543

Linux under Installation using Libuuid (uuid-generate)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.