Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | 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. void strcat(char strDest[], char strSource[])
  28. {
  29.  
  30. int i, j;
  31.  
  32. i = j = 0;
  33. while (strDest[i] != '\0')
  34.         i++;
  35.  
  36. while ((strDest[i++] = strSource[j++]) != '\0')
  37.              ;
  38. }
  39.  
  40.  
  41. int strcmp(const char* string1, const char* string2)
  42. {
  43.  
  44. while (1)
  45. {
  46. if (*string1<*string2)
  47.         return -1;
  48. if (*string1>*string2)
  49.         return 1;
  50.  
  51. if (*string1=='\0')
  52.         return 0;
  53.  
  54. string1++;
  55. string2++;
  56. }
  57.  
  58. }
  59.  
  60.  
  61. void strcpy(char strDest[], const char strSource[])
  62. {
  63. unsigned i;
  64.  
  65. i = 0;
  66. while ((strDest[i] = strSource[i]) != '\0')
  67.         i++;
  68.  
  69. }
  70.  
  71.  
  72. char* strncpy(char *strDest, const char *strSource, unsigned n)
  73. {
  74. unsigned i;
  75.  
  76. if (! n )
  77.         return strDest;
  78.  
  79. i = 0;
  80. while ((strDest[i] = strSource[i]) != '\0')
  81.         if ( (n-1) == i )
  82.                 break;
  83.         else
  84.                 i++;
  85.  
  86. return strDest;
  87. }
  88.  
  89.  
  90. int strlen(const char* string)
  91. {
  92. int i;
  93.  
  94. i=0;
  95. while (*string++) i++;
  96. return i;
  97. }
  98.  
  99.  
  100.  
  101. char* strchr(const char* string, int c)
  102. {
  103.         while (*string)
  104.         {
  105.                 if (*string==c)
  106.                         return (char*)string;
  107.                 string++;
  108.         }      
  109.         return (char*)0;
  110. }
  111.  
  112.