Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include "string.h"
  3.  
  4. void*  memset(void *mem, int c, unsigned size)
  5. {
  6. unsigned i;
  7.  
  8. for ( i = 0; i < size; i++ )
  9.          *((char *)mem+i) = (char) c;
  10.  
  11. return NULL;   
  12. }
  13.  
  14.  
  15. void* memcpy(void *dst, const void *src, unsigned size)
  16. {
  17.  
  18. unsigned i;
  19.  
  20. for ( i = 0; i < size; i++)
  21.         *(char *)(dst+i) = *(char *)(src+i);
  22.  
  23. return NULL;
  24. }
  25.  
  26.  
  27. int memcmp(const void* buf1, const void* buf2, int count)
  28. {
  29. int i;
  30. for (i=0;i<count;i++)
  31.         {
  32.         if (*(unsigned char*)buf1<*(unsigned char*)buf2)
  33.                 return -1;
  34.         if (*(unsigned char*)buf1>*(unsigned char*)buf2)                       
  35.                 return 1;
  36.         }
  37. return 0;
  38. }
  39.  
  40. void strcat(char strDest[], char strSource[])
  41. {
  42.  
  43. int i, j;
  44.  
  45. i = j = 0;
  46. while (strDest[i] != '\0')
  47.         i++;
  48.  
  49. while ((strDest[i++] = strSource[j++]) != '\0')
  50.              ;
  51. }
  52.  
  53.  
  54. int strcmp(const char* string1, const char* string2)
  55. {
  56.  
  57. while (1)
  58. {
  59. if (*string1<*string2)
  60.         return -1;
  61. if (*string1>*string2)
  62.         return 1;
  63.  
  64. if (*string1=='\0')
  65.         return 0;
  66.  
  67. string1++;
  68. string2++;
  69. }
  70.  
  71. }
  72.  
  73.  
  74. void strcpy(char strDest[], const char strSource[])
  75. {
  76. unsigned i;
  77.  
  78. i = 0;
  79. while ((strDest[i] = strSource[i]) != '\0')
  80.         i++;
  81.  
  82. }
  83.  
  84.  
  85. char* strncpy(char *strDest, const char *strSource, unsigned n)
  86. {
  87. unsigned i;
  88.  
  89. if (! n )
  90.         return strDest;
  91.  
  92. i = 0;
  93. while ((strDest[i] = strSource[i]) != '\0')
  94.         if ( (n-1) == i )
  95.                 break;
  96.         else
  97.                 i++;
  98.  
  99. return strDest;
  100. }
  101.  
  102.  
  103. int strlen(const char* string)
  104. {
  105. int i;
  106.  
  107. i=0;
  108. while (*string++) i++;
  109. return i;
  110. }
  111.  
  112.  
  113.  
  114. char* strchr(const char* string, int c)
  115. {
  116.         while (*string)
  117.         {
  118.                 if (*string==c)
  119.                         return (char*)string;
  120.                 string++;
  121.         }      
  122.         return (char*)0;
  123. }
  124.  
  125.