- Timestamp:
- Jul 17, 2017, 2:48:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/string.c
r1 r223 32 32 register const char *ptr = str; 33 33 34 if (str == NULL)35 return 0;36 37 34 while (*ptr) ptr++; 38 35 … … 46 43 register const char *ptr = str; 47 44 48 if (str == NULL)49 return 0;50 51 45 while (*ptr && (maxlen-- > 0)) ptr++; 52 46 … … 58 52 const char * s2 ) 59 53 { 60 if((s1 == NULL) || (s2 == NULL)) 61 return s1 - s2; 62 54 63 55 while (*s1 && *s1 == *s2) 64 56 { … … 66 58 s2 ++; 67 59 } 68 60 69 61 return (*s1 - *s2); 70 62 } … … 75 67 uint32_t n ) 76 68 { 77 if ((s1 == NULL) || (s2 == NULL) || (n == 0))78 return s1 - s2; 79 69 if (n == 0) 70 return s1 - s2; // XXX ??? 71 80 72 while (*s1 && (*s1 == *s2) && (n > 1)) 81 73 { … … 84 76 n--; 85 77 } 86 78 87 79 return (*s1 - *s2); 88 80 } … … 95 87 char c2; 96 88 97 if((str1 == NULL) || (str2 == NULL))98 return str1 - str2;99 100 89 do{ 101 90 c1 = toupper(*++str1); 102 91 c2 = toupper(*++str2); 103 92 }while(c1 && c1 == c2); 104 93 105 94 return (c1 - c2); 106 95 } … … 113 102 char *dst_ptr = dest; 114 103 115 if(!dest || !src)116 return dest;117 118 104 while(*src_ptr) 119 105 *(dst_ptr++) = *(src_ptr++); 120 106 121 107 *dst_ptr = 0; 122 108 return dest; … … 135 121 for (; i < n; i++) 136 122 dest[i] = '\0'; 137 123 138 124 return dest; 139 125 } … … 143 129 int c ) 144 130 { 145 if(s == NULL)146 return (char*)s;147 148 131 while(*s && *s != (char) c) 149 132 s++; … … 151 134 if(*s == (char) c) 152 135 return (char*)s; 153 136 154 137 return NULL; 155 138 } … … 159 142 int c ) 160 143 { 161 162 144 register char ch; 145 register const char * l =0; 163 146 164 165 166 167 168 147 ch = c; 148 for (;;) { 149 if (*t == ch) l=t; if (!*t) return (char*)l; ++t; 150 } 151 return (char*)l; 169 152 } 170 153
Note: See TracChangeset
for help on using the changeset viewer.