Subversion Repositories Kolibri OS

Rev

Rev 1005 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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