UC_MEMSET



#if UCHAR_MAX <= INT_MAX

    #include <string.h>

    #define UC_MEMSET(p,uc,len) (memset((p),(uc),(len)))        /* Normal memset will work just fine */

#elif INT_MIN != -INT_MAX
    
    /* It's two's complement */

    #include <string.h> 

    #define UC_AS_INT(x) UC_AS_INT_Internal( (char unsigned)(x) ) 

    #define UC_AS_INT_Internal(x) ( x > INT_MAX  \ 
                                  ?   -(int)(UCHAR_MAX - x)  - 1 \ 
                                  : (int)x ) 

    #define UC_MEMSET(p,uc,len) (memset((p),UC_AS_INT((uc)),(len))) 

#else

     #include <stddef.h>

     static void *uc_memset(void *const pv,char unsigned const val,size_t const len) 
     { 
         char *p = pv; 
         char const *const pend = p + len; 

         while (pend != p)
             *p++ = val; 

         return pv; 
     } 

     #define UC_MEMSET(p,uc,len) (uc_memset(p,uc,len)) 

#endif


Virjacode Home