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

# dkcStdio.h

Go to the documentation of this file.

    00001
    00010 #ifndef dkutil_c_Stdio__h
    00011 #define dkutil_c_Stdio__h
    00012
    00013
    00014 #include <stdio.h>
    00015 #include <string.h>
    00016 #include "dkcOSIndependent.h"
    00017
    00018 #ifdef __cplusplus
    00019 namespace dkutil{
    00027
    00028         inline int dkmemcpy(void *dest,size_t size1,const void *src,size_t size2){
    00029                 if(size1 < size2) return edk_FAILED;
    00030                 ::memcpy(dest,src,size2);
    00031                 return edk_SUCCEEDED;
    00032         }
    00040
    00041         inline int dkmemmove( void *dest,size_t size1,const void *src, size_t size2 ){
    00042                 if(size1 < size2) return edk_FAILED;
    00043                 ::memmove(dest,src,size2);
    00044                 return edk_SUCCEEDED;
    00045         }
    00052 #       if 0
    00053         inline int dksprintf(char *buff,size_t bufsize,char *format,...){
    00054                 BOOST_STATIC_ASSERT(!"つかうなー！");
    00055                 //char buff[2048]="";
    00056                 size_t buffnum=bufsize;
    00057                 char *origin = format;
    00058                 {
    00059                         va_list VaList;
    00060                         va_start( VaList , origin ) ;
    00061                         int r;
    00062                         r = _vsnprintf( buff ,buffnum - 1, origin , VaList );
    00063                         if(0 > r){
    00064                                 return edk_FAILED;
    00065                         }else{
    00066                                 buff[r+1] = '\0';
    00067                         }
    00068                         va_end( VaList );
    00069                 }
    00070
    00071                 return edk_SUCCEEDED;
    00072         }
    00073 #       endif //end of if 0
    00074
    00089         inline int dkstrcpy(char *dest,size_t size1,const char *src,size_t srclen){
    00090                 if(size1 <= srclen) return edk_FAILED;
    00091                 ::strncpy(dest,src,srclen);
    00092                 //if(dest[srclen] != '\0') return edk_FAILED;
    00093                 dest[srclen] = '\0';//0を入れるからsrclen + 1ではない。
    00094                 return edk_SUCCEEDED;
    00095         }
    00097         inline dkstrcpy(BYTE *dest,size_t size1,const BYTE *src,size_t srclen)
    00098         {
    00099                 return dkstrcpy((char *)dest,size1,(const char *)src,srclen);
    00100         }
    00109
    00110         inline int dkstrcpy_amap(char *dest,size_t size1,const char *src,size_t srclen){
    00111 #       ifndef NDEBUG
    00112                 assert(!(0 == size1 && 0 == srclen));
    00113 #       endif
    00114                 if(size1 <= srclen){//ここは<=か！？
    00115                         ::strncpy(dest,src,size1);
    00116                         dest[size1 - 1] = '\0';
    00117                         return edk_Not_Satisfactory;
    00118                 }else{
    00119                         ::strncpy(dest,src,srclen);
    00120                         dest[srclen] = '\0';
    00121                         return edk_SUCCEEDED;
    00122                 }
    00123         }
    00124         inline int dkstrcpy_amap2(char *dest,size_t size1,const char *src){
    00125                 return dkstrcpy_amap(dest,size1,src,strlen(src));
    00126         }
    00139         inline int dkstrcat(char *dest,size_t destsize,size_t destlen,
    00140                 const char *src,size_t srclen)
    00141         {
    00142                 //destlen + srclen + NULL文字
    00143                 if(destsize < destlen + srclen + 1)     return edk_FAILED;
    00144                 ::strncat(dest,src,srclen);
    00145                 return edk_SUCCEEDED;
    00146         }
    00148         inline int dkstrcat2(char *dest,size_t destsize,const char *src){
    00149                 return dkstrcat(dest,destsize,strlen(dest),src,strlen(src));
    00150         }
    00152         inline int dkstrcat_amap(char *dest,size_t destsize,size_t destlen,
    00153                 const char *src,size_t srclen)
    00154         {
    00155                 //destlen + srclen + NULL文字
    00156                 int result = edk_SUCCEEDED;
    00157                 size_t lsize = destlen + srclen + 1;
    00158                 if(destsize < lsize)
    00159                 {//オーバーしてたら･･･
    00160                         srclen = lsize - destsize - 1;
    00161                         result = edk_Not_Satisfactory;
    00162                 }
    00163                 ::strncat(dest,src,srclen);
    00164                 //dest[destlen + srclen - 1] = '\0';
    00165                 return result;
    00166         }
    00168         inline int dkstrcat_amap2(char *dest,size_t destsize,const char *src){
    00169                 return dkstrcat_amap(dest,destsize,strlen(dest),src,strlen(src));
    00170         }
    00171
    00180         inline int dkmemcmp( const void *buf1,size_t buf1PermitSize,
    00181                 const void *buf2, size_t count )
    00182         {
    00183                 if(buf1PermitSize < count)return edk_LogicError;
    00184                 if(0 !=::memcmp(buf1,buf2,count))return edk_FAILED;
    00185                 return edk_SUCCEEDED;
    00186         }
    00187
    00196
    00197         template<typename TYPE_>
    00198         inline int WINAPI dkcmp_base(const TYPE_ *b1,size_t b1size,
    00199                 const TYPE_ *b2,size_t b2size)
    00200         {
    00201                 if(b1size < b2size) return edk_LogicError;
    00202                 int result = edk_SUCCEEDED;
    00203                 //とりあえずマッチするか確かめる。
    00204                 for(size_t i=0;i<b2size;i++)
    00205                 {
    00206                         if(b1[i] != b2[i])
    00207                         {
    00208                                 result = edk_FAILED;
    00209                                 break;
    00210                         }
    00211                 }
    00212                 return result;
    00213         }
    00214
    00223         inline int dkstrcmp(const char *b1,size_t b1size,const char *b2,size_t b2size)
    00224         {
    00225                 //検索する文字列が多いとおかしいのでエラー
    00226                 if(b1size < b2size) return edk_LogicError;
    00227
    00228                 int result = edk_SUCCEEDED;
    00229                 if(b2size % 4 == 0)
    00230                 {//無理やりintで検索
    00231                         size_t fb1size = b1size / 4;
    00232                         size_t fb2size = b2size / 4;
    00233                         const int *fb1 = (const int *)b1;
    00234                         const int *fb2 = (const int *)b2;
    00235                         return dkcmp_base(fb1,fb1size,fb2,fb2size);
    00236                 }
    00237                 //else
    00238                 //{
    00239                         //basic な検索･･･。
    00240                         return dkcmp_base(b1,b1size,b2,b2size);
    00241                 //}
    00242         }
    00249
    00250         template<typename INTEGER_>
    00251         inline size_t beam(INTEGER_ num){
    00252
    00253                 size_t b = 0 ;
    00254                 for(INTEGER_ i = 10 ; num >= i ; i *= 10 ){
    00255                         b ++ ;
    00256                 }
    00257                 return b;
    00258         }
    00259
    00261         inline void memswap( void *va, void *vb, size_t size )
    00262         {
    00263                 char *ca;
    00264                 char *cb;
    00265                 char  cTmp;
    00266                 for( ca = (char *)va, cb = (char *)vb; size > 0; size--, ca++, cb++ )
    00267                 {
    00268                         cTmp = *ca;
    00269                         *ca  = *cb;
    00270                         *cb  = cTmp;
    00271                 }
    00272         }//memswap
    00273
    00274
    00275
    00278         inline void memreverse( void *array, size_t num, size_t size )
    00279         {
    00280                 char *l;
    00281                 char *r;
    00282
    00283                 l = (char *)array;
    00284                 r = (char *)array + ((num-1) * size);
    00285                 for( ; l < r; l = l+size, r = r-size )
    00286                         memswap( l, r, size );
    00287         }//memreverse
    00288
    00289
    00292         inline void memrrotate( void *array, size_t shift, size_t num, size_t size )
    00293         {
    00294                 memreverse( array,                      num,       size ); // 012345678 -> 876543210
    00295                 memreverse( array,                      shift,     size ); // 876543210 -> 678543210
    00296                 memreverse( (char *)array+(size*shift), num-shift, size ); // 678543210 -> 678012345
    00297         }//memrrotate
    00298
    00299
    00302         inline void memlrotate( void *array, size_t shift, size_t num, size_t size )
    00303         {
    00304                 memreverse( array,                      shift,     size ); // 012345678 -> 210345678
    00305                 memreverse( (char *)array+(size*shift), num-shift, size ); // 210345678 -> 210876543
    00306                 memreverse( array,                      num,       size ); // 210876543 -> 345678012
    00307         }//memlrotate
    00308 }//end of dkutil namespace
    00309 #if 0
    00310 inline int WINAPI dkc_memcpy(void *dest,size_t size1,const void *src,size_t size2){
    00311         return dkutil::dkmemcpy(dest,size1,src,size2);
    00312 }
    00313 inline int WINAPI dkc_strcpy(char *dest,size_t size1,const char *src,size_t srclen){
    00314         return dkutil::dkstrcpy(dest,size1,src,srclen);
    00315 }
    00316 inline int WINAPI dkc_strcpy(BYTE *dest,size_t size1,const BYTE *src,size_t srclen){
    00317         return dkc_strcpy((char *)dest,size1,(const char *)src,srclen);
    00318 }
    00319 inline int WINAPI dkc_strcpy_amap(char *dest,size_t size1,const char *src,size_t srclen){
    00320         return dkutil::dkstrcpy_amap(dest,size1,src,srclen);
    00321 }
    00323 inline int WINAPI dkc_strcpy_amap2(char *dest,size_t size1,const char *src){
    00324         return dkutil::dkstrcpy_amap2(dest,size1,src);
    00325 }
    00327 inline int WINAPI dkc_strcat(char *dest,size_t destsize,size_t destlen,
    00328                 const char *src,size_t srclen)
    00329 {
    00330                 return dkutil::dkstrcat(dest,destsize,destlen,src,srclen);
    00331 }
    00333 inline int WINAPI dkc_strcat2(char *dest,size_t destsize,const char *src){
    00334         return dkutil::dkstrcat2(dest,destsize,src);
    00335 }
    00337 inline int WINAPI dkc_strcat_amap(char *dest,size_t destsize,size_t destlen,
    00338                 const char *src,size_t srclen)
    00339 {
    00340         return dkutil::dkstrcat_amap(dest,destsize,destlen,src,srclen);
    00341 }
    00343 inline int WINAPI dkc_strcat_amap2(char *dest,size_t destsize,const char *src){
    00344         return dkutil::dkstrcat_amap2(dest,destsize,src);
    00345 }
    00347 inline int WINAPI dkc_memcmp( const void *buf1,size_t buf1PermitSize,
    00348         const void *buf2, size_t count )
    00349 {
    00350         return dkutil::dkmemcmp(buf1,buf1PermitSize,buf2,count);
    00351 }
    00352 inline int WINAPI dkc_strcmp(const char *b1,size_t b1size,const char *b2,size_t b2size)
    00353 {
    00354         return dkutil::dkstrcmp(b1,b1size,b2,b2size);
    00355 }
    00356 inline size_t dkc_beam(int num){
    00357         return dkutil::beam(num);
    00358 }
    00359
    00361 inline void dkc_memswap( void *va, void *vb, size_t size )
    00362 {
    00363         dkutil::memswap(va,vb,size);
    00364 }
    00365
    00367 inline void dkc_memreverse( void *array, size_t num, size_t size )
    00368 {
    00369         dkutil::memreverse(array,num,size);
    00370 }
    00372 inline void dkc_memrrotate( void *array, size_t shift, size_t num, size_t size )
    00373 {
    00374         dkutil::memrrotate(array,shift,num,size);
    00375 }
    00376
    00378 inline void dkc_memlrotate( void *array, size_t shift, size_t num, size_t size )
    00379 {
    00380         dkutil::memlrotate(array,shift,num,size);
    00381 }
    00382 #endif//end of if 0
    00383
    00384 #else //for C lang
    00385
    00386 #endif //end of __cplusplus
    00387
    00388 DKC_EXTERN int WINAPI dkc_memcpy(void *dest,size_t size1,const void *src,size_t size2);
    00389
    00390 DKC_EXTERN int WINAPI dkc_memmove(void *dest,size_t size1,const void *src, size_t size2 );
    00391
    00392
    00393 DKC_EXTERN int WINAPI dkc_strcpy(char *dest,size_t size1,const char *src,size_t srclen);
    00394
    00395 DKC_EXTERN int WINAPI dkc_strcpy_amap(char *dest,size_t size1,const char *src,size_t srclen);
    00397 DKC_EXTERN int WINAPI dkc_strcpy_amap2(char *dest,size_t size1,const char *src);
    00399 DKC_EXTERN int WINAPI dkc_strcat(char *dest,size_t destsize,size_t destlen,
    00400                 const char *src,size_t srclen);
    00402 DKC_EXTERN int WINAPI dkc_strcat2(char *dest,size_t destsize,const char *src);
    00404 DKC_EXTERN int WINAPI dkc_strcat_amap(char *dest,size_t destsize,size_t destlen,
    00405                 const char *src,size_t srclen);
    00407 DKC_EXTERN int WINAPI dkc_strcat_amap2(char *dest,size_t destsize,const char *src);
    00409 DKC_EXTERN int WINAPI dkc_memcmp( const void *buf1,size_t buf1PermitSize,
    00410         const void *buf2, size_t count );
    00411 DKC_EXTERN int WINAPI dkc_strcmp(const char *b1,size_t b1size,const char *b2,size_t b2size);
    00412 DKC_EXTERN size_t dkc_beam(int num);
    00413
    00415 DKC_EXTERN void dkc_memswap( void *va, void *vb, size_t size );
    00416
    00418 DKC_EXTERN void dkc_memreverse( void *array, size_t num, size_t size );
    00420 DKC_EXTERN void dkc_memrrotate( void *array, size_t shift, size_t num, size_t size );
    00421
    00423 DKC_EXTERN void dkc_memlrotate( void *array, size_t shift, size_t num, size_t size );
    00424
    00433
    00434 DKC_EXTERN int dkc_stream_swap(char *memory,size_t size,size_t point);
    00435
    00436
    00437
    00438 #if 0
    00439
    00468 DKC_EXTERN int WINAPI strnicmp(
    00469     const char *string1, const char *string2, size_t count);
    00470
    00471 #endif
    00472
    00473 #endif //end of include once