📄 一个uuid生成算法的c语言实现 --- win32版本.mht
字号:
data2;</SPAN></DIV>
<DIV style=3D"MARGIN-LEFT: 21pt" align=3Dleft><SPAN=20
style=3D"FONT-SIZE: 9pt"> <SPAN=20
style=3D"COLOR: blue">unsigned</SPAN> <SPAN=20
style=3D"COLOR: blue">short</SPAN> =
data3;</SPAN></DIV>
<DIV style=3D"MARGIN-LEFT: 21pt" align=3Dleft><SPAN=20
style=3D"FONT-SIZE: 9pt"> <SPAN=20
style=3D"COLOR: blue">unsigned</SPAN> <SPAN style=3D"COLOR: =
blue">char</SPAN>=20
data4[8];</SPAN></DIV>
<DIV style=3D"MARGIN-LEFT: 21pt"><SPAN style=3D"FONT-SIZE: 9pt">}=20
uuid_t;</SPAN></DIV>
<DIV> </DIV>
<DIV>=E5=AE=83=E7=9A=84=E7=BB=93=E6=9E=84=E5=A4=A7=E5=B0=8F=E4=B8=BA16=E4=
=B8=AA=E5=AD=97=E8=8A=82=E3=80=82=E5=8D=B3sizeof(uuid_t)=3D=3D16=E4=B8=BA=
TRUE=E3=80=82=E5=86=99=E6=88=9016=E8=BF=9B=E5=88=B6=E5=AD=97=E7=AC=A6=E4=B8=
=B2=E7=9A=84=E6=A0=BC=E5=BC=8F=EF=BC=8C=E4=B8=80=E8=88=AC=E4=B8=BA=EF=BC=9A=
</DIV>
<DIV style=3D"TEXT-INDENT: 21pt"><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: =
#a31515">"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"</SPAN></DIV>
<DIV> </DIV>
<DIV=20
style=3D"TEXT-INDENT: =
21pt">=E4=B8=8A=E9=9D=A2=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=BD=A2=E5=BC=
=8F=EF=BC=8C=E5=8D=A0=E7=94=A836=E4=B8=AA=E5=AD=97=E7=AC=A6=EF=BC=8C=E4=B8=
=8D=E5=8C=85=E6=8B=AC=E7=BB=93=E5=B0=BE=E7=A9=BA=E5=AD=97=E7=AC=A6=E2=80=99=
\0=E2=80=99=E3=80=82=E6=89=80=E4=BB=A5=EF=BC=8C=E8=A6=81=E6=83=B3=E5=AE=B9=
=E7=BA=B3=E4=B8=80=E4=B8=AAUUID=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E5=BF=
=85=E9=A1=BB=E5=A3=B0=E6=98=8E=E4=B8=BA=E4=B8=80=E4=B8=AAchar[36+1]=E7=9A=
=84=E5=AD=97=E7=AC=A6=E6=95=B0=E7=BB=84=E3=80=82</DIV>
<DIV> </DIV>
<DIV=20
style=3D"TEXT-INDENT: =
21pt">=E4=BB=A5=E8=BD=AF=E4=BB=B6=E7=AE=97=E6=B3=95=E5=AE=9E=E7=8E=B0UUID=
=E9=9D=9E=E5=B8=B8=E6=9C=89=E7=8E=B0=E5=AE=9E=E6=84=8F=E4=B9=89=E3=80=82=E5=
=8F=82=E8=80=83RFC4122=E6=96=87=E6=A1=A3=E5=92=8C=E5=85=B6=E4=BB=96=E4=B8=
=80=E4=BA=9B=E5=BC=80=E6=BA=90=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=88=91=E5=86=99=
=E4=BA=86=E4=B8=80=E4=B8=AAWIN32=E4=B8=8B=E7=9A=84UUID=E5=AE=9E=E7=8E=B0C=
=E8=AF=AD=E8=A8=80=E7=A8=8B=E5=BA=8F=E2=80=94=E2=80=94UUID32.c=E3=80=82=E7=
=A8=8B=E5=BA=8F=E7=AC=A6=E5=90=88RFC4122=E6=A0=87=E5=87=86=E3=80=82=E7=A8=
=8B=E5=BA=8F=E4=B8=8D=E4=BD=86=E5=AE=9E=E7=8E=B0=E5=88=9B=E5=BB=BAUUID=E5=
=92=8CUUID=20
String=EF=BC=8C=E8=BF=98=E5=8F=AF=E4=BB=A5=E5=AF=B9UUID=E8=BF=9B=E8=A1=8C=
=E5=AD=97=E7=AC=A6=E5=92=8C=E6=97=B6=E9=97=B4=E4=B8=8A=E7=9A=84=E6=AF=94=E8=
=BE=83=E3=80=82=E8=BF=98=E5=8F=AF=E4=BB=A5=E4=BB=8EUUID=E4=BB=8E=E6=8F=90=
=E5=8F=96=E6=97=B6=E9=97=B4=E6=88=B3=EF=BC=88=E7=B2=BE=E5=BA=A6=E5=88=B0=E7=
=A7=92=EF=BC=89=E3=80=82=E5=A4=B4=E6=96=87=E4=BB=B6uuid32.h=E5=AE=9A=E4=B9=
=89=E5=A6=82=E4=B8=8B=EF=BC=9A</DIV>
<DIV style=3D"TEXT-INDENT: 21pt"></DIV>
<DIV style=3D"TEXT-INDENT: 21pt">
<DIV=20
style=3D"BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; =
BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: =
#e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; =
WIDTH: 95%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: =
windowtext 0.5pt solid">
<DIV><SPAN style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> uuid32.h <BR> 2007-09-15 Last&n=
bsp;created by cheungmine.<BR> Partly rig=
hts reserved by cheungmine.<BR></SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR>#ifndef UUID32_H_INCLUDED<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">#define</SPAN><SPAN=20
style=3D"COLOR: #000000"> UUID32_H_INCLUDED</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR><BR>#include </SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #000000">stdlib.h</SPAN><SPAN=20
style=3D"COLOR: #000000">></SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>#include </SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #000000">assert.h</SPAN><SPAN=20
style=3D"COLOR: #000000">></SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>#include </SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN style=3D"COLOR: =
#000000">.h</SPAN><SPAN=20
style=3D"COLOR: #000000">></SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>#include </SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #000000">memory.h</SPAN><SPAN=20
style=3D"COLOR: #000000">></SPAN><SPAN=20
style=3D"COLOR: #000000"><BR><BR>#include </SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN=20
style=3D"COLOR: #000000">cdatatype.h</SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR><BR>typedef </SPAN><SPAN=20
style=3D"COLOR: #0000ff">struct</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> _timestamp_t<BR>{<BR> BYTE &nb=
sp; tm_sec; &nb=
sp; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Seconds after minute (0 =E2=80=93 =
;59). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR> BYTE tm_min;&=
nbsp; &n=
bsp; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Minutes after hour (0 =E2=80=93 5=
9). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR> BYTE tm_hour;=
<=
/SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Hours after midnight (0 =E2=80=93 =
;23). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR> BYTE tm_mday;=
<=
/SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Day of month (1 =E2=80=93 31).&nb=
sp;</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR> BYTE tm_mon;&=
nbsp; &n=
bsp; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Month (0 =E2=80=93 11; January =3D=
0). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR> BYTE tm_wday;=
<=
/SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Day of week (0 =E2=80=93 6; =
Sunday =3D 0). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">short</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> tm_year; &n=
bsp; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Year (current year minus 1900). <=
/SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">short</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> tm_yday; &n=
bsp; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Day of year (0 =E2=80=93 365;&nbs=
p;January 1 =3D 0). </SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">long</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> tm_fraction; &nbs=
p; </SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000"> Fraction little than 1 second </S=
PAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR>} timestamp_t;<BR><BR>typedef </SPAN><SPAN=20
style=3D"COLOR: #0000ff">struct</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> _uuid_t<BR>{<BR> unsigned </SP=
AN><SPAN=20
style=3D"COLOR: #0000ff">long</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> data1;<BR> unsign=
ed </SPAN><SPAN=20
style=3D"COLOR: #0000ff">short</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> data2;<BR> unsign=
ed </SPAN><SPAN=20
style=3D"COLOR: #0000ff">short</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> data3;<BR> unsign=
ed </SPAN><SPAN=20
style=3D"COLOR: #0000ff">char</SPAN><SPAN=20
style=3D"COLOR: #000000"> data4[</SPAN><SPAN=20
style=3D"COLOR: #000000">8</SPAN><SPAN=20
style=3D"COLOR: #000000">];<BR>} uuid_t;<BR><BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR> * Checks whether the given s=
tring matches the UUID format.<BR> * =
params:<BR> * [in] uui=
d - the potential UUID string<BR> * &n=
bsp; return <BR> * TRUE=
if the given string is a UUID, F=
ALSE otherwise<BR> *</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>BOOL is_uuid_string(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">const</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">char</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN style=3D"COLOR: =
#000000">*</SPAN><SPAN=20
style=3D"COLOR: #000000">uuid);<BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR> * Generates a new UUID. The&=
nbsp;UUID is a time-based time 1 UUID.<BR>&=
nbsp;* A random per-process node identifier =
;is used to avoid keeping global<BR> * =
;state and maintaining inter-process synchronization.=
<BR> *</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN style=3D"COLOR: =
#000000"><BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">void</SPAN><SPAN=20
style=3D"COLOR: #000000"> uuid_create(uuid_t</SPAN><SPAN=20
style=3D"COLOR: #000000">*</SPAN><SPAN=20
style=3D"COLOR: #000000"> uuid);<BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR> * Generates a new UUID strin=
g. The returned UUID is a time-based t=
ime 1 UUID.<BR> * A random per-process =
;node identifier is used to avoid keeping&n=
bsp;global<BR> * state and maintaining inter-pro=
cess synchronization.<BR> * return UUID st=
ring (newly allocated)<BR> *</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN style=3D"COLOR: =
#000000"><BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">char</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN style=3D"COLOR: =
#000000">*</SPAN><SPAN=20
style=3D"COLOR: #000000">uuid_create_string(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">void</SPAN><SPAN=20
style=3D"COLOR: #000000">);<BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR> * Generates a name-based (type&nb=
sp;3) UUID string from the given external<B=
R> * identifier. The special namespace UUID=
is used as the namespace of<BR> *&nbs=
p;the generated UUID.<BR> * params<BR> *&n=
bsp; [in] external - the exter=
nal identifier<BR> * return <BR> * &n=
bsp; UUID string (newly allocated)<BR>&nb=
sp;*</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN style=3D"COLOR: =
#000000"><BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">void</SPAN><SPAN=20
style=3D"COLOR: #000000"> uuid_create_external(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">const</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">char</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN style=3D"COLOR: =
#000000">*</SPAN><SPAN=20
style=3D"COLOR: #000000">external, uuid_t</SPAN><SPAN=20
style=3D"COLOR: #000000">*</SPAN><SPAN=20
style=3D"COLOR: #000000"> uuid);<BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR> * Translate a uuid_t to a&nb=
sp;uuid string<BR> * return UUID string<BR=
> *</SPAN><SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN style=3D"COLOR: =
#000000"><BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">char</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN style=3D"COLOR: =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -