Subversion Repositories HelenOS

Rev

Rev 1787 | Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1787 Rev 1896
Line 98... Line 98...
98
 
98
 
99
/** Compare two NULL terminated strings
99
/** Compare two NULL terminated strings
100
 *
100
 *
101
 * Do a char-by-char comparison of two NULL terminated strings.
101
 * Do a char-by-char comparison of two NULL terminated strings.
102
 * The strings are considered equal iff they consist of the same
102
 * The strings are considered equal iff they consist of the same
-
 
103
 * characters on the minimum of their lengths.
-
 
104
 *
-
 
105
 * @param src First string to compare.
-
 
106
 * @param dst Second string to compare.
-
 
107
 *
-
 
108
 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
-
 
109
 *
-
 
110
 */
-
 
111
int strcmp(const char *src, const char *dst)
-
 
112
{
-
 
113
    for (; *src && *dst; src++, dst++) {
-
 
114
        if (*src < *dst)
-
 
115
            return -1;
-
 
116
        if (*src > *dst)
-
 
117
            return 1;
-
 
118
    }
-
 
119
    if (*src == *dst)
-
 
120
        return 0;
-
 
121
    if (!*src)
-
 
122
        return -1;
-
 
123
    return 1;
-
 
124
}
-
 
125
 
-
 
126
 
-
 
127
/** Compare two NULL terminated strings
-
 
128
 *
-
 
129
 * Do a char-by-char comparison of two NULL terminated strings.
-
 
130
 * The strings are considered equal iff they consist of the same
103
 * characters on the minimum of their lengths and specified maximal
131
 * characters on the minimum of their lengths and specified maximal
104
 * length.
132
 * length.
105
 *
133
 *
106
 * @param src First string to compare.
134
 * @param src First string to compare.
107
 * @param dst Second string to compare.
135
 * @param dst Second string to compare.
Line 112... Line 140...
112
 */
140
 */
113
int strncmp(const char *src, const char *dst, size_t len)
141
int strncmp(const char *src, const char *dst, size_t len)
114
{
142
{
115
    int i;
143
    int i;
116
   
144
   
117
    i = 0;
-
 
118
    for (;*src && *dst && i < len;src++,dst++,i++) {
145
    for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
119
        if (*src < *dst)
146
        if (*src < *dst)
120
            return -1;
147
            return -1;
121
        if (*src > *dst)
148
        if (*src > *dst)
122
            return 1;
149
            return 1;
123
    }
150
    }
Line 126... Line 153...
126
    if (!*src)
153
    if (!*src)
127
        return -1;
154
        return -1;
128
    return 1;
155
    return 1;
129
}
156
}
130
 
157
 
-
 
158
 
-
 
159
 
131
/** Copy NULL terminated string.
160
/** Copy NULL terminated string.
132
 *
161
 *
133
 * Copy at most 'len' characters from string 'src' to 'dest'.
162
 * Copy at most 'len' characters from string 'src' to 'dest'.
134
 * If 'src' is shorter than 'len', '\0' is inserted behind the
163
 * If 'src' is shorter than 'len', '\0' is inserted behind the
135
 * last copied character.
164
 * last copied character.