Main Page | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# dkcOSIndependent.h

Go to the documentation of this file.

    00001
    00007 #ifndef dkutil_c_OSIndependent__h
    00008 #define dkutil_c_OSIndependent__h
    00009
    00010 #include "dkcDefined.h"
    00011
    00012
    00013
    00014 #ifndef WIN32
    00015
    00016 #ifndef ULONGLONG
    00017 #       define ULONGLONG unsigned long long int
    00018 #endif
    00019
    00020 #ifndef LONGLONG
    00021 #       define LONGLONG long long int
    00022 #endif
    00023
    00024
    00025 #ifndef ULONGLONG_MAX
    00026 #       define ULONGLONG_MAX DKINGYO_ULONGLONG_MAX
    00027 #endif
    00028 #ifndef LONGLONG_MAX
    00029 #       define LONGLONG_MAX DKINGYO_LONGLONG_MAX
    00030 #endif
    00031 #ifndef LONGLONG_MIN
    00032 #       define LONGLONG_MIN DKINGYO_LONGLONG_MIN
    00033 #endif
    00034
    00035 #ifndef TRUE
    00036 #       define TRUE 1
    00037 #endif
    00038 #ifndef FALSE
    00039 #       define FALSE 0
    00040 #endif
    00041
    00042 #ifndef NULL
    00043 #       define NULL 0
    00044 #endif
    00045
    00046 #       define dkcdPATH_SEP '/'
    00047 #       define dkcdPATH_SEP_STR "/"
    00048 #       define dkcdPATH_LIST_SEP ':'
    00049 #       define dkcdPATH_LIST_SEP_STR ":"
    00050 #       define dkcmIS_PATH_SEP(c) (dkcdPATH_SEP==(c))
    00051 /*.,:;*/
    00052 #       define dkcmIS_INVALID_FILENAME_CHAR(c) ( ((c) =='\\') || ((c)=='/') || ((c)=='*') || ((c)=='?') \
    00053                 || ((c)== '"') || ((c) == '<') || ((c) == '>') || ((c) == '|') )
    00054
    00055 #       define dkcmIS_INVALID_FOLDERNAME_CHAR(c) \
    00056         dkcmIS_INVALID_FILENAME_CHAR(c)
    00057
    00058 #define dkcmIS_INVALID_PATH_CHAR(c) \
    00059         ( ( (c)=='\\') || ((c)=='*') || ((c)=='?') || ((c)== '"') || \
    00060         ((c) == '<') || ((c) == '>') || ((c) == '|') )
    00061
    00062 //reallocの関数の型
    00063 typedef void *(*DKC_REALLOC_F_TYPE)(void *,size_t);
    00064
    00065 typedef int BOOL;
    00066 typedef unsigned char BYTE;
    00067
    00068
    00069
    00070 //#error "I don't multithread define..."
    00071 #ifdef _MT//MultiThread
    00072 #       define dkcdMultiThread
    00073 #endif
    00074
    00075 #ifndef CALLBACK
    00076 #       define CALLBACK
    00077 #endif
    00078 #ifndef WINAPI
    00079 #       define WINAPI
    00080 #endif
    00081
    00082 #else
    00083
    00084 #ifdef _MSC_VER
    00085 #       ifdef _DEBUG
    00086 #               ifndef DEBUG
    00087 #                       define DEBUG
    00088 #               endif
    00089 #       else
    00090 #               ifndef NDEBUG
    00091 #                       define NDEBUG
    00092 #               endif
    00093 #       endif
    00094
    00095 #       pragma warning(disable:4115)//union{ } struct{ }
    00096 #       pragma warning(disable:4100)//引数が関数の本体で 1 度も参照されません。
    00097 #       pragma warning(disable:4206)//プリプロセス後のファイルが空です。 #if 0 #endif
    00098 #       pragma warning(disable:4710)//場合によってはｲﾝﾗｲﾝ処理を行いません。
    00099 #       pragma warning(disable:4505)//参照されていないﾛｰｶﾙ関数は削除されました。
    00100 #endif
    00101
    00102 # include <windows.h>
    00103
    00104
    00105
    00106
    00107
    00108 #       ifndef CALLBACK
    00109 #               define CALLBACK __stdcall
    00110 #       endif
    00111 #       ifndef WINAPI
    00112 #               define WINAPI __stdcall
    00113 #       endif
    00114
    00115
    00116
    00117 #       define dkcdPATH_SEP '\\'
    00118 #       define dkcdPATH_SEP_STR "\\"
    00119 #       define dkcdPATH_LIST_SEP ';'
    00120 #       define dkcdPATH_LIST_SEP_STR ";"
    00121 #       define dkcmIS_PATH_SEP(c) (dkcdPATH_SEP==(c) || '/'==(c))
    00122
    00124 #       define dkcmIS_INVALID_FILENAME_CHAR(c) ( ((c) =='\\') || ((c)=='/') || ((c)=='*') || ((c)=='?') \
    00125                 || ((c)== '"') || ((c) == '<') || ((c) == '>') || ((c) == '|') || (':'== (c)) )
    00126
    00127 #       define dkcmIS_INVALID_FOLDERNAME_CHAR(c) \
    00128         dkcmIS_INVALID_FILENAME_CHAR(c)
    00129
    00131 #       define dkcmIS_INVALID_PATH_CHAR(c) \
    00132         ((c)=='*') || ((c)=='?') || ((c)== '"') || \
    00133         ((c) == '<') || ((c) == '>') || ((c) == '|')
    00134
    00135 #ifdef _MT
    00136 #       define dkcdMultiThread
    00137 #endif
    00138
    00139 #ifdef _MSC_VER
    00140 #ifdef DEBUG
    00141 #               pragma comment(linker,"/NODEFAULTLIB:LIBC")
    00142 #               pragma comment(linker,"/NODEFAULTLIB:LIBCMT")
    00143 #       ifdef dkcdMultiThread
    00144 #               pragma comment(linker,"/NODEFAULTLIB:LIBCD")
    00145 #       else
    00146 #               pragma comment(linker,"/NODEFAULTLIB:LIBCMTD")
    00147 #       endif
    00148 #else
    00149 #               pragma comment(linker,"/NODEFAULTLIB:LIBCD")
    00150 #               pragma comment(linker,"/NODEFAULTLIB:LIBCMTD")
    00151 #       ifdef dkcdMultiThread
    00152 #               pragma comment(linker,"/NODEFAULTLIB:LIBC")
    00153 #       else
    00154 #               pragma comment(linker,"/NODEFAULTLIB:LIBCMT")
    00155 #       endif
    00156 #endif
    00157 #endif //end of _MSC_VER
    00158
    00159 #endif //end of  #ifndef WIN32
    00160
    00161
    00162 #ifdef WIN32
    00163         //reallocの関数の型
    00164         typedef void *(WINAPIV *DKC_REALLOC_F_TYPE)(void *,size_t);
    00165
    00166 #else
    00167
    00168         typedef void *(*DKC_REALLOC_F_TYPE)(void *,size_t);
    00169
    00170 #endif
    00171
    00172 #ifndef DKC_INLINE
    00173 #       if _MSC_VER >= 1100
    00174 #               define DKC_INLINE _inline
    00175 #       else
    00176 #               define DKC_INLINE
    00177 #       endif
    00178 #endif
    00179
    00180 #ifdef WIN32
    00181 #       define DKC_EXPORT __declspec(dllexport)
    00182 #       define DKC_IMPORT __declspec(dllimport)
    00183 #       ifdef USE_DKCDLL
    00184 #               ifdef DKCDLL_EXPORTS
    00185 #                       define DKC_EXTERN DKUTIL_EXTERN DKC_EXPORT
    00186 #               else
    00187 #                       define DKC_EXTERN DKUTIL_EXTERN DKC_INPORT
    00188 #               endif
    00189 #       else
    00190 #               ifdef _MSC_VER
    00191 #                       define DKC_EXTERN DKUTIL_EXTERN DKC_INLINE
    00192 #               else
    00193 #                       define DKC_EXTERN DKUTIL_EXTERN
    00194 #               endif
    00195 #       endif
    00196 #else
    00197 #       define DKC_EXPORT
    00198 #       define DKC_IMPORT
    00199 #       define DKC_EXTERN DKUTIL_EXTERN
    00200 #endif
    00201
    00202
    00203 #ifdef __BORLANDC__
    00204 #       include <dir.h>
    00205 #else
    00206 #       include <direct.h>
    00207 #endif
    00208
    00209
    00210 #ifndef dkcdMAXPATH
    00211 #       if defined(PATH_MAX)
    00212 #               define dkcdMAXPATH   PATH_MAX
    00213
    00214 #       elif defined(MAX_PATH)
    00215 #               define dkcdMAXPATH   MAX_PATH
    00216
    00217 #       elif  defined(_MAX_PATH)
    00218 #               define dkcdMAXPATH   _MAX_PATH
    00219
    00220 #       else
    00221 #               define dkcdMAXPATH   1024
    00222
    00223 #       endif
    00224 #endif
    00225
    00226 #ifndef dkcdMAXPATH_LEN
    00227 #       define dkcdMAXPATH_LEN dkcdMAXPATH
    00228 #endif
    00229
    00230 /* 何事も例外を考えるのが大切だ。って事でbufferは普通の２倍取得する･･･。（ｵｲ
    00231         追記：
    00232         見事に予想は的中してバッファサイズは約２倍無いと危ない条件がある事が分かった。
    00233         */
    00234
    00235
    00236 #ifndef dkcdMAXPATH_BUFFER
    00237
    00238 #       define dkcdMAXPATH_BUFFER dkcdMAXPATH * 2
    00239 #endif
    00240
    00241
    00242
    00243 #ifndef MAYBE
    00244 #       define MAYBE 2
    00245 #endif
    00246
    00247 typedef struct dkc_4char{
    00248         signed char mode1,mode2,mode3,mode4;
    00249 }DKC_4CHAR;
    00250
    00251
    00252
    00253
    00254 #ifdef __cplusplus
    00255
    00256 namespace dkutil{
    00257
    00258
    00268
    00269 inline bool SaveBinary(const void *data,size_t size,const char *fname,const char *mode="wb"){//="wb"
    00270         FILE *fp;
    00271         fp = fopen( fname , mode ) ;//wb
    00272         if(fp==NULL) return false;
    00273         fwrite( data , size  , 1 , fp ) ;
    00274         //fwrite( data , sizeof(size)  , 1 , fp ) ;
    00275         fclose( fp ) ;
    00276         return true;
    00277 }
    00278
    00286
    00287 inline bool LoadBinary(void *data,size_t size,const char *fname,const char *mode="rb" ){//="rb"
    00288         FILE *fp ;
    00289         fp = fopen( fname , mode ) ;//rb
    00290         if(fp==NULL)return false;
    00291         fread( data ,  size , 1 , fp ) ;
    00292         //fread( data , sizeof(size)  , 1 , fp ) ;
    00293         fclose( fp ) ;
    00294         return true;
    00295 }
    00296
    00297 inline bool SaveText(const char *text,size_t length,const char *fname,const char *mode="wt"){
    00298         return SaveBinary(text,length,fname,mode);
    00299 }
    00300 inline bool LoadText(char *text,size_t length,const char *fname,const char *mode="rt"){
    00301         return LoadBinary(text,length,fname,mode);
    00302 }
    00303
    00304
    00305
    00306 }//end of dkutil namespace
    00307
    00308
    00309 #else //for c lang
    00310
    00312 DKC_EXTERN BOOL WINAPI dkcIsNativePathString(const char *s,size_t size);
    00313
    00314
    00315 #endif //end of __cplusplus
    00316
    00317 /*
    00318 @param OldSize[in] 元のメモリ領域のサイズ
    00319 @param ExpandSize[in] 足りないメモリ領域のサイズ
    00320 @return 多分、理想系のサイズ？カナ？
    00321 @note reallocする時の最適なメモリサイズを計算する。
    00322 (内部実装はちょくちょく変わります。
    00323 */
    00324
    00325 DKC_EXTERN  size_t dkcReallocateSizeFunction(size_t OldSize,size_t ExpandSize);
    00326
    00327 DKC_EXTERN  void* WINAPIV dkcAllocate(size_t size);
    00328
    00329 DKC_EXTERN  int WINAPIV dkcFree(void **p);
    00330
    00331 DKC_EXTERN  int WINAPI dkcReallocate(
    00332         void **NewPtr,size_t NewSize,void **OldPtr
    00333 );
    00334
    00342
    00343 DKC_EXTERN int WINAPI dkcReallocateEx(
    00344         DKC_REALLOC_F_TYPE your_realloc,void **NewPtr,size_t NewSize,
    00345         void **OldPtr
    00346 );
    00347
    00357 DKC_EXTERN int WINAPI dkcReallocateAutoExpand(
    00358         DKC_REALLOC_F_TYPE your_realloc,void **NewPtr,
    00359         void **OldPtr,size_t OldSize,size_t *reallocated_size
    00360 );
    00361
    00365 DKC_EXTERN void WINAPI
    00366         dkcSwap(void *p1,void *p2,size_t size);
    00373 DKC_EXTERN void WINAPI dkcSwapFast(void *p1,void *p2,size_t size);
    00374
    00382 DKC_EXTERN void WINAPI dkcSwap64(ULONGLONG *p1,ULONGLONG *p2,size_t size);
    00383
    00384
    00385
    00386 //#define dkcSwap(p1_,p2_,size) dkcSwap64(p1_,p2_,size)
    00387 /*
    00388 #define dkcSwapFast(p1,p2,size) dkcSwap64(p1,p2,size)
    00389 */
    00390
    00391
    00393 DKC_EXTERN BOOL dkcIs_foepn_mode(const char *s);
    00395 DKC_EXTERN FILE * WINAPI dkcFOpen(const char *filename,const char *mode);
    00397 DKC_EXTERN int WINAPI dkcFClose(FILE **ptr);
    00398
    00400 DKC_EXTERN int WINAPI dkcSaveBinary(const void *data,size_t size,const char *fname);
    00401
    00403 DKC_EXTERN int WINAPI dkcLoadBinary(void *data,size_t size,const char *fname,size_t *readsize);
    00405 DKC_EXTERN int WINAPI dkcSaveText(const char *text,size_t length,const char *fname);
    00407 DKC_EXTERN int WINAPI dkcLoadText(char *text,size_t length,const char *fname,size_t *readsize);
    00409 DKC_EXTERN BOOL WINAPI dkcCreateEmptyFile(const char *filename);
    00410
    00414 DKC_EXTERN int WINAPI dkcErrorMessage(const char *expression,
    00415                                                                                  const char *filename,size_t line,const char *message,...);
    00416
    00417
    00418
    00419 #if defined(DEBUG) || defined(DKUTIL_DEBUG)
    00420 #       define dkcmNOT_ASSERT(ex) ( (ex) && dkcErrorMessage(#ex,__FILE__,__LINE__,NULL) )
    00421 #       define dkcmASSERT(ex) ( (ex) || dkcErrorMessage(#ex,__FILE__,__LINE__,NULL) )
    00422 #       define dkcmNOT_ASSERT_MESSAGE(ex,mes) ( (ex) && dkcErrorMessage(#ex,__FILE__,__LINE__,mes) )
    00423 #       define dkcmASSERT_MESSAGE(ex,mes) ( (ex) || dkcErrorMessage(#ex,__FILE__,__LINE__,mes) )
    00424 #else
    00425 #       define dkcmNOT_ASSERT_MESSAGE(ex,mes) ((void)0)
    00426 #       define dkcmASSERT_MESSAGE(ex,mes) ((void)0)
    00427 #       define dkcmNOT_ASSERT(ex) ((void)0)
    00428 #       define dkcmASSERT(ex) ((void)0)
    00429 #endif
    00430
    00431 #       define dkcmFORCE_NOT_ASSERT(ex) ( (ex) && dkcErrorMessage(#ex,__FILE__,__LINE__,NULL) )
    00432 #       define dkcmFORCE_ASSERT(ex) ( (ex) || dkcErrorMessage(#ex,__FILE__,__LINE__,NULL) )
    00433 #       define dkcmFORCE_NOT_ASSERT_MESSAGE(ex,mes) ( (ex) && dkcErrorMessage(#ex,__FILE__,__LINE__,mes) )
    00434 #       define dkcmFORCE_ASSERT_MESSAGE(ex,mes) ( (ex) || dkcErrorMessage(#ex,__FILE__,__LINE__,mes) )
    00435
    00437 DKC_EXTERN const char *dkcGetPathSep();
    00438
    00439
    00440
    00441 #endif //end of include once