root/include/asm-sparc/string.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. strlen
  2. strcmp
  3. strncmp
  4. strcpy
  5. strncpy
  6. strcat
  7. strncat
  8. strchr
  9. strpbrk
  10. strspn
  11. strtok
  12. memset
  13. memcpy
  14. memmove
  15. memcmp

   1 /* string.h: External definitions for optimized assembly string
   2  *           routines for the Linux Kernel.
   3  *
   4  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   5  */
   6 
   7 #ifndef _SPARC_STRING_H
   8 #define _SPARC_STRING_H
   9 
  10 extern __inline__ size_t strlen(const char * str)
     /* [previous][next][first][last][top][bottom][index][help] */
  11 {
  12   const char *sc;
  13 
  14   for (sc = str; *sc != '\0'; ++sc)
  15     /* nothing */;
  16   return sc - str;
  17 }
  18 
  19 extern __inline__ int strcmp(const char* str1, const char* str2)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21   register signed char __res;
  22 
  23   while (1) {
  24     if ((__res = *str1 - *str2++) != 0 || !*str1++)
  25       break;
  26   }
  27 
  28   return __res;
  29 }
  30 
  31 extern __inline__ int strncmp(const char* str1, const char* str2, size_t strlen)
     /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33   register signed char __res = 0;
  34 
  35   while (strlen) {
  36     if ((__res = *str1 - *str2++) != 0 || !*str1++)
  37       break;
  38     strlen--;
  39   }
  40 
  41   return __res;
  42 }
  43 
  44 
  45 extern __inline__ char *strcpy(char* dest, const char* source)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47   char *tmp = dest;
  48 
  49   while ((*dest++ = *source++) != '\0')
  50     /* nothing */;
  51   return tmp;
  52 }
  53 
  54 extern __inline__ char *strncpy(char *dest, const char *source, size_t cpylen)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56   char *tmp = dest;
  57 
  58   while (cpylen-- && (*dest++ = *source++) != '\0')
  59     /* nothing */;
  60 
  61   return tmp;
  62 }
  63 
  64 extern __inline__ char *strcat(char *dest, const char *src)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66   char *tmp = dest;
  67 
  68   while (*dest)
  69     dest++;
  70   while ((*dest++ = *src++) != '\0')
  71     ;
  72 
  73   return tmp;
  74 }
  75 
  76 extern __inline__ char *strncat(char *dest, const char *src, size_t len)
     /* [previous][next][first][last][top][bottom][index][help] */
  77 {
  78   char *tmp = dest;
  79 
  80   if (len) {
  81     while (*dest)
  82       dest++;
  83     while ((*dest++ = *src++)) {
  84       if (--len == 0)
  85         break;
  86     }
  87   }
  88 
  89   return tmp;
  90 }
  91 
  92 extern __inline__ char *strchr(const char *src, int c)
     /* [previous][next][first][last][top][bottom][index][help] */
  93 {
  94   for(; *src != c; ++src)
  95     if (*src == '\0')
  96       return NULL;
  97   return (char *) src;
  98 }
  99 
 100 extern __inline__ char *strpbrk(const char *cs, const char *ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102   const char *sc1,*sc2;
 103 
 104   for( sc1 = cs; *sc1 != '\0'; ++sc1) {
 105     for( sc2 = ct; *sc2 != '\0'; ++sc2) {
 106       if (*sc1 == *sc2)
 107         return (char *) sc1;
 108     }
 109   }
 110   return NULL;
 111 }
 112 
 113       
 114 extern __inline__ size_t strspn(const char *s, const char *accept)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116   const char *p;
 117   const char *a;
 118   size_t count = 0;
 119 
 120   for (p = s; *p != '\0'; ++p) {
 121     for (a = accept; *a != '\0'; ++a) {
 122       if (*p == *a)
 123         break;
 124     }
 125     if (*a == '\0')
 126       return count;
 127     ++count;
 128   }
 129 
 130   return count;
 131 }
 132 
 133 extern __inline__ char *strtok(char *s, const char *ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135   char *sbegin, *send;
 136 
 137   sbegin  = s ? s : ___strtok;
 138   if (!sbegin) {
 139     return NULL;
 140   }
 141   sbegin += strspn(sbegin,ct);
 142   if (*sbegin == '\0') {
 143     ___strtok = NULL;
 144     return( NULL );
 145   }
 146   send = strpbrk( sbegin, ct);
 147   if (send && *send != '\0')
 148     *send++ = '\0';
 149   ___strtok = send;
 150   return (sbegin);
 151 }
 152         
 153 
 154 extern __inline__ void *memset(void *src, int c, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156   char *xs = (char *) src;
 157 
 158   while (count--)
 159     *xs++ = c;
 160 
 161   return src;
 162 }
 163 
 164 extern __inline__ void *memcpy(void *dest, const void *src, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166   char *tmp = (char *) dest, *s = (char *) src;
 167 
 168   while (count--)
 169     *tmp++ = *s++;
 170 
 171   return dest;
 172 }
 173 
 174 extern __inline__ void *memmove(void *dest, const void *src, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 175 {
 176   char *tmp, *s;
 177 
 178   if (dest <= src) {
 179     tmp = (char *) dest;
 180     s = (char *) src;
 181     while (count--)
 182       *tmp++ = *s++;
 183   }
 184   else {
 185     tmp = (char *) dest + count;
 186     s = (char *) src + count;
 187     while (count--)
 188       *--tmp = *--s;
 189   }
 190 
 191   return dest;
 192 }
 193 
 194 extern __inline__ int memcmp(const void *cs, const void *ct, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196   const unsigned char *su1, *su2;
 197   signed char res = 0;
 198 
 199   for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
 200     if ((res = *su1 - *su2) != 0)
 201       break;
 202   return res;
 203 }
 204 
 205 #endif /* !(_SPARC_STRING_H) */

/* [previous][next][first][last][top][bottom][index][help] */