Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #ifndef NULL
  3. #define NULL ((void*)0)
  4. #endif
  5.  
  6. static inline void*  memset(void *mem, int c, unsigned size)
  7. {
  8. unsigned i;
  9.  
  10. for ( i = 0; i < size; i++ )
  11.          *((char *)mem+i) = (char) c;
  12.  
  13. return NULL;   
  14. }
  15.  
  16.  
  17. static inline void* memcpy(void *dst, const void *src, unsigned size)
  18. {
  19.  
  20. unsigned i;
  21.  
  22. for ( i = 0; i < size; i++)
  23.         *(char *)(dst+i) = *(char *)(src+i);
  24.  
  25. return NULL;
  26. }
  27.  
  28.  
  29. static inline int memcmp(const void* buf1, const void* buf2, int count)
  30. {
  31. int i;
  32. for (i=0;i<count;i++)
  33.         {
  34.         if (*(unsigned char*)buf1<*(unsigned char*)buf2)
  35.                 return -1;
  36.         if (*(unsigned char*)buf1>*(unsigned char*)buf2)                       
  37.                 return 1;
  38.         }
  39. return 0;
  40. }
  41.  
  42. static inline char *strcat(char strDest[], char strSource[])
  43. {
  44.         int i, j;
  45.         i = j = 0;
  46.         while (strDest[i] != '\0') i++;
  47.         while ((strDest[i++] = strSource[j++]) != '\0');
  48.         return strDest;
  49. }
  50.  
  51.  
  52. static inline int strcmp(char* string1,char* string2)
  53. {
  54.  
  55. while (1)
  56. {
  57. if (*string1<*string2)
  58.         return -1;
  59. if (*string1>*string2)
  60.         return 1;
  61.  
  62. if (*string1=='\0')
  63.         return 0;
  64.  
  65. string1++;
  66. string2++;
  67. }
  68.  
  69. }
  70.  
  71. static inline char *strcpy(char strDest[], const char strSource[])
  72. {
  73.         unsigned i;
  74.         i = 0;
  75.         while ((strDest[i] = strSource[i]) != '\0') i++;
  76.         return strDest;
  77. }
  78.  
  79.  
  80. char* strncpy(char *strDest, const char *strSource, unsigned n)
  81. {
  82.         unsigned i;
  83.  
  84.         if (! n )
  85.                 return strDest;
  86.  
  87.         i = 0;
  88.         while ((strDest[i] = strSource[i]) != '\0')
  89.                 if ( (n-1) == i )
  90.                         break;
  91.                 else
  92.                         i++;
  93.  
  94.         return strDest;
  95. }
  96.  
  97.  
  98. static inline int strlen(const char* string)
  99. {
  100.         int i;
  101.  
  102.         i=0;
  103.         while (*string++) i++;
  104.         return i;
  105. }
  106.  
  107.  
  108.  
  109. static inline char* strchr(const char* string, int c)
  110. {
  111.         while (*string)
  112.         {
  113.                 if (*string==c)
  114.                         return (char*)string;
  115.                 string++;
  116.         }      
  117.         return (char*)0;
  118. }
  119.  
  120.  
  121. static inline char* strrchr(const char* string, int c)
  122. {
  123.         char* last_found;
  124.         while (*string)
  125.         {
  126.                 if (*string==c)
  127.                 {
  128.                         last_found = (char*)string;
  129.                 }
  130.                 string++;
  131.         }      
  132.         return last_found;
  133. }
  134.  
  135.  
  136.  
  137. static inline void _itoa(int i, char *s)
  138. {
  139.         int a, b, c, d;
  140.         a = (i - i%1000)/1000;
  141.         b = (i - i%100)/100 - a*10;
  142.         c = (i - i%10)/10 - a*100 - b*10;
  143.         d = i%10;
  144.         s[0] = a + '0';
  145.         s[1] = b + '0';
  146.         s[2] = c + '0';
  147.         s[3] = d + '0';
  148.         s[4] = 0;
  149. }
  150.  
  151.  
  152.  /* reverse:  ïåðåâîðà÷èâàåì ñòðîêó s íà ìåñòå */
  153. static inline void reverse(char s[])
  154.  {
  155.      int i, j;
  156.      char c;
  157.  
  158.      for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
  159.          c = s[i];
  160.          s[i] = s[j];
  161.          s[j] = c;
  162.      }
  163.  }
  164.  
  165.  
  166.  /* itoa:  êîíâåðòèðóåì n â ñèìâîëû â s */
  167. static inline void itoa(int n, char s[])
  168.  {
  169.      int i, sign;
  170.  
  171.      if ((sign = n) < 0)
  172.          n = -n;
  173.      i = 0;
  174.      do {
  175.          s[i++] = n % 10 + '0';
  176.      } while ((n /= 10) > 0);
  177.      if (sign < 0)
  178.          s[i++] = '-';
  179.      s[i] = '\0';
  180.      reverse(s);
  181.  }
  182.  
  183.  
  184.  
  185. static inline int atoi ( char *s )
  186. {
  187.         int i, n;
  188.  
  189.         n = 0;
  190.         for ( i = 0; s[i]!= '\0'; ++i)
  191.                 if ((s[i]<'0') || (s[i]>'9'))
  192.                         return 0;
  193.                 else
  194.                         n = 10 * n + s[i] - '0';
  195.  
  196.         return n;
  197. }
  198.