メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# dkc_misc.h

説明を見る。

    00001
    00008 #ifndef DKUTIL_C_DKC_MISC_H
    00009 #define DKUTIL_C_DKC_MISC_H
    00010
    00011
    00012
    00013 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
    00014 #   pragma once
    00015 #else
    00016
    00017
    00018 #endif
    00019
    00020 #ifdef __cplusplus //C++のみ
    00021
    00022 #   include <limits>
    00023
    00024
    00025 #endif
    00026
    00027
    00028 #include "dkcDefined.h"
    00029 #include <limits.h>
    00030 #include <float.h>
    00031 #include <assert.h>
    00032
    00033 /*
    00034 #define DKUTIL_C_USE_DKUTIL_CSTD
    00035 #ifdef DKUTIL_C_USE_DKUTIL_CSTD
    00036 #define DKUTIL_CSTD_NOT_DEFINE_STDLIB_MACRO
    00037 #   include "dkutil_cstd/stdlib.h"
    00038 #else
    00039 #   include <stdlib.h>
    00040 #endif
    00041 */
    00042 #define DKUTIL_CSTD_NOT_DEFINE_STDLIB_MACRO
    00043 #   include "dkutil_cstd/stdlib.h"
    00044 #   include <stdlib.h>
    00045
    00046 #ifdef __BORLANDC__
    00047 #   include <dir.h>
    00048 #else
    00049 #   include <direct.h>
    00050 #endif
    00051
    00052 #if defined(_WIN32) || defined(__WIN32__)
    00053 #   ifndef WIN32
    00054 #       define WIN32
    00055 #   endif
    00056 #endif
    00057
    00058 //**********************************************************
    00059 //型定義
    00060
    00061 #if defined(_MSC_VER) || defined(WIN32) || defined(__BCPLUSPLUS__)
    00062     typedef unsigned __int64 QWORD;
    00063
    00064 #else
    00065     typedef unsigned long long QWORD;
    00066
    00067 #endif
    00068
    00069
    00070
    00071
    00073 typedef unsigned char dkctBOOL;
    00074 /*
    00075 #ifndef uint32
    00076 typedef unsigned long uint32;
    00077 #endif
    00078
    00079 #ifndef uint16
    00080 typedef unsigned short uint16;
    00081 #endif
    00082
    00083 #ifndef uint8
    00084 typedef unsigned char uint8;
    00085 #endif
    00086 */
    00087
    00088
    00089 #ifndef WIN32
    00090
    00091 #ifndef DWORD
    00092 #   define DWORD        uint32
    00093 #endif
    00094 #ifndef WORD
    00095 #   define WORD         uint16
    00096 #endif
    00097 #ifndef BYTE
    00098 #   define BYTE         uint8
    00099 #endif
    00100
    00101
    00102
    00103
    00104
    00105 #ifndef ULONGLONG
    00106 #   define ULONGLONG unsigned long long int
    00107 #endif
    00108
    00109 #ifndef LONGLONG
    00110 #   define LONGLONG long long int
    00111 #endif
    00112
    00113
    00114 #ifndef TRUE
    00115 #   define TRUE 1
    00116 #endif
    00117 #ifndef FALSE
    00118 #   define FALSE 0
    00119 #endif
    00120
    00121 #ifndef NULL
    00122 #   define NULL 0
    00123 #endif
    00124
    00125 #   define dkcdPATH_SEP '/'
    00126 #   define dkcdPATH_SEP_STR "/"
    00127 #   define dkcdPATH_LIST_SEP ':'
    00128 #   define dkcdPATH_LIST_SEP_STR ":"
    00129 #   define dkcmIS_PATH_SEP(c) (dkcdPATH_SEP==(c))
    00130 /*.,:;*/
    00131 #   define dkcmIS_INVALID_FILENAME_CHAR(c) ( ((c) =='\\') || ((c)=='/') || ((c)=='*') || ((c)=='?') \
    00132         || ((c)== '"') || ((c) == '<') || ((c) == '>') || ((c) == '|') )
    00133
    00134 #   define dkcmIS_INVALID_FOLDERNAME_CHAR(c) \
    00135     dkcmIS_INVALID_FILENAME_CHAR(c)
    00136
    00137 #define dkcmIS_INVALID_PATH_CHAR(c) \
    00138     ( ( (c)=='\\') || ((c)=='*') || ((c)=='?') || ((c)== '"') || \
    00139     ((c) == '<') || ((c) == '>') || ((c) == '|') )
    00140
    00141 //reallocの関数の型
    00142 //typedef void *(*DKC_REALLOC_F_TYPE)(void *,size_t);
    00143
    00144 typedef int BOOL;
    00145 //typedef unsigned char BYTE;
    00146
    00147
    00148
    00149
    00150 #ifndef CALLBACK
    00151 #   define CALLBACK
    00152 #endif
    00153 #ifndef WINAPI
    00154 #   define WINAPI
    00155 #endif
    00156
    00157 #else //else of WIN32
    00158
    00159 #ifdef _MSC_VER
    00160 #   ifdef _DEBUG
    00161 #       ifndef DEBUG
    00162 #           define DEBUG
    00163 #       endif
    00164 #   else
    00165 #       ifndef NDEBUG
    00166 #           define NDEBUG
    00167 #       endif
    00168 #   endif
    00169
    00170 #   pragma warning(disable:4115)//union{ } struct{ }
    00171 #   pragma warning(disable:4100)//引数が関数の本体で 1 度も参照されません。
    00172 #   pragma warning(disable:4206)//プリプロセス後のファイルが空です。 #if 0 #endif
    00173 #   pragma warning(disable:4710)//場合によってはｲﾝﾗｲﾝ処理を行いません。
    00174 #   pragma warning(disable:4505)//参照されていないﾛｰｶﾙ関数は削除されました。
    00175 #endif
    00176
    00177 # include <windows.h>
    00178
    00179
    00180
    00181
    00182 #   ifndef CALLBACK
    00183 #       define CALLBACK __stdcall
    00184 #   endif
    00185 #   ifndef WINAPI
    00186 #       define WINAPI __stdcall
    00187 #   endif
    00188
    00189
    00190
    00191 #   define dkcdPATH_SEP '\\'
    00192 #   define dkcdPATH_SEP_STR "\\"
    00193 #   define dkcdPATH_LIST_SEP ';'
    00194 #   define dkcdPATH_LIST_SEP_STR ";"
    00195 #   define dkcmIS_PATH_SEP(c) (dkcdPATH_SEP==(c) || '/'==(c))
    00196
    00198 #   define dkcmIS_INVALID_FILENAME_CHAR(c) ( ((c) =='\\') || ((c)=='/') || ((c)=='*') || ((c)=='?') \
    00199         || ((c)== '"') || ((c) == '<') || ((c) == '>') || ((c) == '|') || (':'== (c)) )
    00200
    00201 #   define dkcmIS_INVALID_FOLDERNAME_CHAR(c) \
    00202     dkcmIS_INVALID_FILENAME_CHAR(c)
    00203
    00205 #   define dkcmIS_INVALID_PATH_CHAR(c) \
    00206     ((c)=='*') || ((c)=='?') || ((c)== '"') || \
    00207     ((c) == '<') || ((c) == '>') || ((c) == '|')
    00208
    00209 #ifdef _MT
    00210 #   define dkcdMultiThread
    00211 #endif
    00212
    00213 #ifdef _MSC_VER
    00214 #define CRTDBG_MAP_ALLOC
    00215 #   include <crtdbg.h>
    00216 #   ifdef DEBUG
    00217 #       pragma comment(linker,"/NODEFAULTLIB:LIBC")
    00218 #       pragma comment(linker,"/NODEFAULTLIB:LIBCMT")
    00219 #   ifdef dkcdMultiThread
    00220 #       pragma comment(linker,"/NODEFAULTLIB:LIBCD")
    00221 #   else
    00222 #       pragma comment(linker,"/NODEFAULTLIB:LIBCMTD")
    00223 #   endif
    00224 #else
    00225 #       pragma comment(linker,"/NODEFAULTLIB:LIBCD")
    00226 #       pragma comment(linker,"/NODEFAULTLIB:LIBCMTD")
    00227 #   ifdef dkcdMultiThread
    00228 #       pragma comment(linker,"/NODEFAULTLIB:LIBC")
    00229 #   else
    00230 #       pragma comment(linker,"/NODEFAULTLIB:LIBCMT")
    00231 #   endif
    00232 #endif
    00233 #endif //end of _MSC_VER
    00234
    00235 #endif //end of  #ifndef WIN32
    00236
    00237
    00238
    00239 #ifdef WIN32//Windowsならば
    00240
    00241 #define ORDER_DCBA  // chosing Intel in this case
    00242 #define dkcdLITTLE_ENDIAN 1
    00243 #define dkcdBIG_ENDIAN 0
    00244 #else //macとかならば
    00245 #define ORDER_ABCD
    00246 #define dkcdLITTLE_ENDIAN 0
    00247 #define dkcdBIG_ENDIAN 1
    00248 //#define ORDER_ABCD //motorola (Macとか)
    00249 #endif
    00250
    00251 #ifdef ORDER_DCBA   // DCBA - little endian - intel
    00252
    00253     union aword {
    00254       DWORD dword;
    00255       BYTE byte [4];
    00256       struct {
    00257         unsigned int byte3:8;
    00258         unsigned int byte2:8;
    00259         unsigned int byte1:8;
    00260         unsigned int byte0:8;
    00261       } w;
    00262     };
    00263
    00264 union dkc4ByteUnionLittleEndianBase{
    00265     DWORD dword;
    00266     BYTE byte [4];
    00267     struct {
    00268       unsigned int byte0:8;
    00269       unsigned int byte1:8;
    00270       unsigned int byte2:8;
    00271       unsigned int byte3:8;
    00272     } w;
    00273 };
    00274 #endif
    00275
    00276 #ifdef ORDER_ABCD   // ABCD - big endian - motorola
    00277     union aword {
    00278       DWORD dword;
    00279       BYTE byte [4];
    00280       struct {
    00281         unsigned int byte0:8;
    00282         unsigned int byte1:8;
    00283         unsigned int byte2:8;
    00284         unsigned int byte3:8;
    00285       } w;
    00286     };
    00287     union dkc4ByteUnionLittleEndianBase{
    00288         DWORD dword;
    00289         BYTE byte [4];
    00290         struct {
    00291             unsigned int byte3:8;
    00292         unsigned int byte2:8;
    00293         unsigned int byte1:8;
    00294         unsigned int byte0:8;
    00295         } w;
    00296 };
    00297 #endif
    00298
    00299 #ifdef ORDER_BADC   // BADC - vax
    00300     union aword {
    00301       DWORD dword;
    00302       BYTE byte [4];
    00303       struct {
    00304         unsigned int byte1:8;
    00305         unsigned int byte0:8;
    00306         unsigned int byte3:8;
    00307         unsigned int byte2:8;
    00308       } w;
    00309 };
    00310 #endif
    00311
    00312 typedef union aword DKC_4BYTE_UNION_BIG_ENDIAN_BASE;
    00313
    00314 typedef union dkc4ByteUnionLittleEndianBase DKC_4BYTE_UNION_LITTLE_ENDIAN_BASE;
    00315
    00316 typedef union dkc_2int32_to_int64{
    00317     struct{
    00318         LONG LowPart;
    00319         LONG HighPart;
    00320     }u;
    00321     LONGLONG QuadPart;
    00322 }DKC_TWOINT32_TO_INT64;
    00323 /*
    00324 #ifdef WIN32
    00325     typedef DKC_4BYTE_UNION_LITTLE_ENDIAN_BASE DKC_4BYTE_UNION;
    00326 */
    00327
    00328
    00329
    00330 #ifdef WIN32
    00331     typedef void (WINAPIV *DKC_FREE_F_TYPE)(void *);
    00332     typedef void *(WINAPIV *DKC_MALLOC_F_TYPE)(size_t);
    00334     typedef void *(WINAPIV *DKC_REALLOC_F_TYPE)(void *,size_t);
    00336     //typedef int (WINAPI *PROC)();
    00337     typedef PROC DKC_WINAPI_PROC_F_TYPE ;
    00338 #else
    00339     typedef void (*DKC_FREE_F_TYPE)(void *);
    00340     typedef void *(*DKC_MALLOC_F_TYPE)(size_t);
    00341     typedef void *(*DKC_REALLOC_F_TYPE)(void *,size_t);
    00342     typedef void *DKC_WINAPI_PROC_F_TYPE;
    00343 #endif
    00344
    00346 typedef BOOL (*DKC_STD_CALLBACK)(void *peculiar,void *user);
    00347
    00348
    00349 //**********************************************************
    00350 //limits
    00351
    00352 #ifndef ULONGLONG_MAX
    00353 #   define ULONGLONG_MAX DKINGYO_ULONGLONG_MAX
    00354 #endif
    00355 #ifndef LONGLONG_MAX
    00356 #   define LONGLONG_MAX DKINGYO_LONGLONG_MAX
    00357 #endif
    00358 #ifndef LONGLONG_MIN
    00359 #   define LONGLONG_MIN DKINGYO_LONGLONG_MIN
    00360 #endif
    00361
    00362
    00363
    00364 #ifndef dkcdMAXPATH
    00365 #   if defined(PATH_MAX)
    00366 #       define dkcdMAXPATH   PATH_MAX
    00367
    00368 #   elif defined(MAX_PATH)
    00369 #       define dkcdMAXPATH   MAX_PATH
    00370
    00371 #   elif  defined(_MAX_PATH)
    00372 #       define dkcdMAXPATH   _MAX_PATH
    00373
    00374 #   else
    00375 #       define dkcdMAXPATH   1024
    00376
    00377 #   endif
    00378 #endif
    00379
    00380 #ifndef dkcdMAXPATH_LEN
    00381 #   define dkcdMAXPATH_LEN dkcdMAXPATH
    00382 #endif
    00383
    00384 /* 何事も例外を考えるのが大切だ。って事でbufferは普通の２倍取得する･･･。（ｵｲ
    00385     追記：
    00386     見事に予想は的中してバッファサイズは約２倍無いと危ない条件がある事が分かった。
    00387     */
    00388
    00389
    00390 #ifndef dkcdMAXPATH_BUFFER
    00391
    00396
    00397 #   define dkcdMAXPATH_BUFFER (dkcdMAXPATH * 2 + 2)
    00398 #endif
    00399
    00400
    00401 #ifndef dkcdMAXPATH_FIXED_SIZE
    00402
    00403 #   define dkcdMAXPATH_FIXED_SIZE 2050
    00404
    00405 #endif
    00406
    00407 #ifndef MAYBE
    00408 #   define MAYBE 2
    00409 #endif
    00410
    00411
    00412
    00413
    00414 typedef struct dkc_4char{
    00415     signed char mode1,mode2,mode3,mode4;
    00416 }DKC_4CHAR;
    00417
    00418
    00419 //**********************************************************
    00420 //インライン関数
    00421
    00422 DKC_INLINE void *dkcAllocateFast_INL(size_t size){
    00423     return malloc(size);
    00424 }
    00425 DKC_INLINE void *dkcAllocateFill_INL(size_t size,uint8 fill){
    00426     void *p = dkcAllocateFast_INL(size);
    00427     if(NULL==p) return NULL;
    00428     memset(p,fill,size);
    00429     return p;
    00430 }
    00431
    00432 DKC_INLINE void* dkcAllocate_INL(size_t size){
    00433     return dkcAllocateFill_INL(size,0);
    00434 /*void *ptr;
    00435     ptr = dkcAllocateFast(size);
    00436     if(NULL==ptr) return NULL;
    00437     memset(ptr,0,size);
    00438     return ptr;
    00439     */
    00440 }
    00441
    00442 DKC_INLINE int  dkcFree_INL(void **p){
    00443     if(!*p) return edk_FAILED;
    00444     free(*p);
    00445     *p = NULL;
    00446     return edk_SUCCEEDED;
    00447 }
    00448
    00449 #endif //end of include once