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.1 - (show annotations) (download) (as text)
Mon Nov 22 08:25:16 2004 UTC (19 years, 4 months ago) by youi
Branch: MAIN
File MIME type: text/x-c++src
initial version.

1 /*
2 * Abstract Layerの各機能がよく使う関数をここで定義する.
3 *
4 * $Revision$
5 * $Log$
6 *
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include "common.h"
12
13 /**
14 *
15 * 与えられた文字列を複製し,そのアドレスを返す.
16 *
17 * @param text
18 * @return 複製した文字列のアドレス
19 * @return 0 複製に失敗
20 *
21 */
22 char* str_dup( const char* text )
23 {
24 if( text == 0 ) return 0;
25 char* ptr = new char[ strlen( text ) + 1 ];
26 if( ptr == 0 ) return 0;
27 strcpy( ptr , text );
28 return ptr;
29 }
30
31 /**
32 *
33 * newtextで指定された文字列を複製し,そのアドレスを*dstptrに代入する.<br>
34 * 成功したら,それまで*dstptrが参照していた領域を解放する.<br>
35 * 途中で失敗した場合は*dstptrの内容は書き換えられない.<br>
36 * newtext==0のときは,*dstptrが参照する領域を解放し,空文字を新規に作成してそのアドレスを*dstptrに代入する.<br>
37 *
38 * @param newtext *dstptrに代入したい文字列
39 * @param dstptr 複製したnewtextのアドレスを代入するポインタ変数へのポインタ
40 * @return dstptrに代入したアドレス 失敗時は処理前のdstptr
41 *
42 */
43 char* setValue( char** dstptr, const char* newtext )
44 {
45 char* ptr;
46
47 // newtextが0なら,*dstptrが参照するメモリ領域を解放し,
48 // *dstptrには新規作成した空文字のアドレスを代入
49 if( newtext == 0 ){
50 ptr = str_dup( "" );
51 }else{
52 ptr = str_dup( newtext );
53 }
54 if( ptr != 0 ){
55 if( *dstptr != 0 ) delete[] *dstptr;
56 *dstptr = ptr;
57 }
58 return *dstptr;
59 }

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