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.3 - (show annotations) (download) (as text)
Fri Nov 26 05:13:40 2004 UTC (19 years, 4 months ago) by aga
Branch: MAIN
Changes since 1.2: +19 -1 lines
File MIME type: text/x-c++src
・userid_t, groupid_tをunsigned int に修正.
・unsignedIntToString()を作成.

1 /*
2 * Abstract Layer????罘??純?????鋎帥???∽?違???????у?臂?????鐚?/span>
3 *
4 * $Revision: 1.2 $
5 * $Log: common.cc,v $
6 * Revision 1.2 2004/11/26 03:29:43 aga
7 * ??ntToString()??篏???.
8 *
9 * Revision 1.1 2004/11/22 08:25:16 youi
10 * initial version.
11 *
12 *
13 */
14
15 #include <stdio.h>
16 #include <string.h>
17 #include "common.h"
18
19 /**
20 *
21 * 筝???????????絖?????茲?茖純??鐚??????≪?????鴻??菴???鐚?/span>
22 *
23 * @param text
24 * @return 茲?茖純??????絖??????≪??????/span>
25 * @return 0 茲?茖純??け??
26 *
27 */
28 char* str_dup( const char* text )
29 {
30 if( text == 0 ) return 0;
31 char* ptr = new char[ strlen( text ) + 1 ];
32 if( ptr == 0 ) return 0;
33 strcpy( ptr , text );
34 return ptr;
35 }
36
37 /**
38 *
39 * newtext?ф??絎?????????絖?????茲?茖純??鐚??????≪?????鴻??*dstptr??撮?ャ????.<br>
40 * ??????????鐚??????障??dstptr?????с??????????????茹f?障????.<br>
41 * ??筝??уけ???????翫????dstptr????絎鴻???吾??????????????鐚?lt;br>
42 * newtext==0?????????*dstptr?????с??????????茹f?障??鐚?腥堺??絖????域???????????????≪?????鴻??*dstptr??撮?ャ????.<br>
43 *
44 * @param newtext *dstptr??撮?ャ????????絖???
45 * @param dstptr 茲?茖純????newtext???≪?????鴻??篁e?ャ???????ゃ?潟?水??違?吾?????ゃ?潟??/span>
46 * @return dstptr??撮?ャ?????≪????? 紊掩??????????????stptr
47 *
48 */
49 char* setValue( char** dstptr, const char* newtext )
50 {
51 char* ptr;
52
53 // newtext??0????鐚?*dstptr?????с?????<?≪????????茹f?障??鐚?
54 // *dstptr?????域?篏???????腥堺??絖????≪?????鴻??篁e??/span>
55 if( newtext == 0 ){
56 ptr = str_dup( "" );
57 }else{
58 ptr = str_dup( newtext );
59 }
60 if( ptr != 0 ){
61 if( *dstptr != 0 ) delete[] *dstptr;
62 *dstptr = ptr;
63 }
64 return *dstptr;
65 }
66
67 /**
68 *
69 * int????絖??????????
70 *
71 * @param i 紊??????鴻???医??/span>
72 * @return 紊???緇?????絖???
73 *
74 */
75 string intToString( int i ){
76 char buf[sizeof(int)*3+1+1+1]; // n???ゃ??????3n+1罅?篁ヤ???膃?垩??罅???\0??罅?
77 snprintf( buf, sizeof(buf), "%d", i );
78 string s( buf );
79 return s;
80 }
81
82 /**
83 *
84 * unsigned int????絖??????????
85 *
86 * @param i 紊??????鴻???医??/span>
87 * @return 紊???緇?????絖???
88 *
89 */
90 string unsignedIntToString( unsigned int i ){
91 char buf[sizeof(int)*3+1+1]; // n???ゃ??????3n+1罅?篁ヤ???\0??罅?
92 snprintf( buf, sizeof(buf), "%u", i );
93 string s( buf );
94 return s;
95 }
96
97
98

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