Subversion Repositories HelenOS

Rev

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

Rev 1881 Rev 1896
Line 55... Line 55...
55
 
55
 
56
/** Compare two NULL terminated strings
56
/** Compare two NULL terminated strings
57
 *
57
 *
58
 * Do a char-by-char comparison of two NULL terminated strings.
58
 * Do a char-by-char comparison of two NULL terminated strings.
59
 * The strings are considered equal iff they consist of the same
59
 * The strings are considered equal iff they consist of the same
-
 
60
 * characters on the minimum of their lengths.
-
 
61
 *
-
 
62
 * @param src First string to compare.
-
 
63
 * @param dst Second string to compare.
-
 
64
 *
-
 
65
 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
-
 
66
 *
-
 
67
 */
-
 
68
int strcmp(const char *src, const char *dst)
-
 
69
{
-
 
70
    for (; *src && *dst; src++, dst++) {
-
 
71
        if (*src < *dst)
-
 
72
            return -1;
-
 
73
        if (*src > *dst)
-
 
74
            return 1;
-
 
75
    }
-
 
76
    if (*src == *dst)
-
 
77
        return 0;
-
 
78
    if (!*src)
-
 
79
        return -1;
-
 
80
    return 1;
-
 
81
}
-
 
82
 
-
 
83
 
-
 
84
/** Compare two NULL terminated strings
-
 
85
 *
-
 
86
 * Do a char-by-char comparison of two NULL terminated strings.
-
 
87
 * The strings are considered equal iff they consist of the same
60
 * characters on the minimum of their lengths and specified maximal
88
 * characters on the minimum of their lengths and specified maximal
61
 * length.
89
 * length.
62
 *
90
 *
63
 * @param src First string to compare.
91
 * @param src First string to compare.
64
 * @param dst Second string to compare.
92
 * @param dst Second string to compare.
Line 69... Line 97...
69
 */
97
 */
70
int strncmp(const char *src, const char *dst, size_t len)
98
int strncmp(const char *src, const char *dst, size_t len)
71
{
99
{
72
    int i;
100
    int i;
73
   
101
   
74
    i = 0;
-
 
75
    for (;*src && *dst && i < len;src++,dst++,i++) {
102
    for (i = 0; *src && *dst && i < len; src++, dst++, i++) {
76
        if (*src < *dst)
103
        if (*src < *dst)
77
            return -1;
104
            return -1;
78
        if (*src > *dst)
105
        if (*src > *dst)
79
            return 1;
106
            return 1;
80
    }
107
    }