Develop and Download Open Source Software

Browse CVS Repository

Contents of /xoonips/AL/common.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Sat Jan 22 05:38:03 2005 UTC (19 years, 2 months ago) by youi
Branch: MAIN
CVS Tags: mv_to_sourceforge_20050217, demo20050128
Changes since 1.4: +30 -1 lines
File MIME type: text/x-c++src
md5strを定義した.

1 /*
2 * Abstract Layer????罘??純?????鋎帥???∽?違???????у?臂?????鐚?/span>
3 *
4 * $Revision: 1.4 $
5 * $Log: common.cc,v $
6 * Revision 1.4 2005/01/06 07:17:15 youi
7 * VC toolkit篏睡??????nprintf??fltused???臂???菴遵??.
8 *
9 * Revision 1.3 2004/11/26 05:13:40 aga
10 * ??serid_t, groupid_t??unsigned int ??信罩?
11 * ??nsignedIntToString()??篏???.
12 *
13 * Revision 1.2 2004/11/26 03:29:43 aga
14 * ??ntToString()??篏???.
15 *
16 * Revision 1.1 2004/11/22 08:25:16 youi
17 * initial version.
18 *
19 *
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include "common.h"
25
26 #if defined(_MSC_VER)
27 #define snprintf _snprintf
28 int _fltused = 0x9875;
29 #endif
30
31 /**
32 *
33 * data??D5????激?ュ?ゃ??羆???鐚???絖??????????鐚???絎?????????絖???????????/span>
34 * str???吾??莨若??.
35 *
36 *
37 *
38 */
39 char* md5str( char str[MD5_DIGEST_STRING_LENGTH], unsigned char* data, int len )
40 {
41 MD5_CTX c;
42 unsigned char buf[MD5_DIGEST_LENGTH];
43 static const char hexdigit[]="0123456789abcdef";
44
45 MD5_Init( &c );
46 MD5_Update( &c, data, len );
47 MD5_Final( buf, &c );
48
49 for( int i = 0 ; i < MD5_DIGEST_LENGTH ; i++ ){
50 str[i*2] = hexdigit[buf[i]>>4];
51 str[i*2+1] = hexdigit[buf[i] & 0x0f];
52 }
53 str[MD5_DIGEST_LENGTH*2] = '\0';
54 return str;
55 }
56
57 /**
58 *
59 * 筝???????????絖?????茲?茖純??鐚??????≪?????鴻??菴???鐚?/span>
60 *
61 * @param text
62 * @return 茲?茖純??????絖??????≪??????/span>
63 * @return 0 茲?茖純??け??
64 *
65 */
66 char* str_dup( const char* text )
67 {
68 if( text == 0 ) return 0;
69 char* ptr = new char[ strlen( text ) + 1 ];
70 if( ptr == 0 ) return 0;
71 strcpy( ptr , text );
72 return ptr;
73 }
74
75 /**
76 *
77 * newtext?ф??絎?????????絖?????茲?茖純??鐚??????≪?????鴻??*dstptr??撮?ャ????.<br>
78 * ??????????鐚??????障??dstptr?????с??????????????茹f?障????.<br>
79 * ??筝??уけ???????翫????dstptr????絎鴻???吾??????????????鐚?lt;br>
80 * newtext==0?????????*dstptr?????с??????????茹f?障??鐚?腥堺??絖????域???????????????≪?????鴻??*dstptr??撮?ャ????.<br>
81 *
82 * @param newtext *dstptr??撮?ャ????????絖???
83 * @param dstptr 茲?茖純????newtext???≪?????鴻??篁e?ャ???????ゃ?潟?水??違?吾?????ゃ?潟??/span>
84 * @return dstptr??撮?ャ?????≪????? 紊掩??????????????stptr
85 *
86 */
87 char* setValue( char** dstptr, const char* newtext )
88 {
89 char* ptr;
90
91 // newtext??0????鐚?*dstptr?????с?????<?≪????????茹f?障??鐚?
92 // *dstptr?????域?篏???????腥堺??絖????≪?????鴻??篁e??/span>
93 if( newtext == 0 ){
94 ptr = str_dup( "" );
95 }else{
96 ptr = str_dup( newtext );
97 }
98 if( ptr != 0 ){
99 if( *dstptr != 0 ) delete[] *dstptr;
100 *dstptr = ptr;
101 }
102 return *dstptr;
103 }
104
105 /**
106 *
107 * int????絖??????????
108 *
109 * @param i 紊??????鴻???医??/span>
110 * @return 紊???緇?????絖???
111 *
112 */
113 string intToString( int i ){
114 char buf[sizeof(int)*3+1+1+1]; // n???ゃ??????3n+1罅?篁ヤ???膃?垩??罅???\0??罅?
115 snprintf( buf, sizeof(buf), "%d", i );
116 string s( buf );
117 return s;
118 }
119
120 /**
121 *
122 * unsigned int????絖??????????
123 *
124 * @param i 紊??????鴻???医??/span>
125 * @return 紊???緇?????絖???
126 *
127 */
128 string unsignedIntToString( unsigned int i ){
129 char buf[sizeof(int)*3+1+1]; // n???ゃ??????3n+1罅?篁ヤ???\0??罅?
130 snprintf( buf, sizeof(buf), "%u", i );
131 string s( buf );
132 return s;
133 }
134
135
136

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26