Subversion Repositories HelenOS

Rev

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

Rev 3707 Rev 4011
Line 75... Line 75...
75
    else
75
    else
76
        printf("cpu: halted\n");
76
        printf("cpu: halted\n");
77
    cpu_halt();
77
    cpu_halt();
78
}
78
}
79
 
79
 
80
/** Return number of characters in a string.
-
 
81
 *
-
 
82
 * @param str NULL terminated string.
-
 
83
 *
-
 
84
 * @return Number of characters in str.
-
 
85
 */
-
 
86
size_t strlen(const char *str)
-
 
87
{
-
 
88
    int i;
-
 
89
   
-
 
90
    for (i = 0; str[i]; i++)
-
 
91
        ;
-
 
92
   
-
 
93
    return i;
-
 
94
}
-
 
95
 
-
 
96
/** Compare two NULL terminated strings
-
 
97
 *
-
 
98
 * Do a char-by-char comparison of two NULL terminated strings.
-
 
99
 * The strings are considered equal iff they consist of the same
-
 
100
 * characters on the minimum of their lengths.
-
 
101
 *
-
 
102
 * @param src First string to compare.
-
 
103
 * @param dst Second string to compare.
-
 
104
 *
-
 
105
 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
-
 
106
 *
-
 
107
 */
-
 
108
int strcmp(const char *src, const char *dst)
-
 
109
{
-
 
110
    for (; *src && *dst; src++, dst++) {
-
 
111
        if (*src < *dst)
-
 
112
            return -1;
-
 
113
        if (*src > *dst)
-
 
114
            return 1;
-
 
115
    }
-
 
116
    if (*src == *dst)
-
 
117
        return 0;
-
 
118
    if (!*src)
-
 
119
        return -1;
-
 
120
    return 1;
-
 
121
}
-
 
122
 
-
 
123
 
-
 
124
/** Compare two NULL terminated strings
-
 
125
 *
-
 
126
 * Do a char-by-char comparison of two NULL terminated strings.
-
 
127
 * The strings are considered equal iff they consist of the same
-
 
128
 * characters on the minimum of their lengths and specified maximal
-
 
129
 * length.
-
 
130
 *
-
 
131
 * @param src First string to compare.
-
 
132
 * @param dst Second string to compare.
-
 
133
 * @param len Maximal length for comparison.
-
 
134
 *
-
 
135
 * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
-
 
136
 *
-
 
137
 */
-
 
138
int strncmp(const char *src, const char *dst, size_t len)
-
 
139
{
-
 
140
    unsigned int i;
-
 
141
   
-
 
142
    for (i = 0; (*src) && (*dst) && (i < len); src++, dst++, i++) {
-
 
143
        if (*src < *dst)
-
 
144
            return -1;
-
 
145
        if (*src > *dst)
-
 
146
            return 1;
-
 
147
    }
-
 
148
    if (i == len || *src == *dst)
-
 
149
        return 0;
-
 
150
    if (!*src)
-
 
151
        return -1;
-
 
152
    return 1;
-
 
153
}
-
 
154
 
-
 
155
 
-
 
156
 
-
 
157
/** Copy NULL terminated string.
-
 
158
 *
-
 
159
 * Copy at most 'len' characters from string 'src' to 'dest'.
-
 
160
 * If 'src' is shorter than 'len', '\0' is inserted behind the
-
 
161
 * last copied character.
-
 
162
 *
-
 
163
 * @param src Source string.
-
 
164
 * @param dest Destination buffer.
-
 
165
 * @param len Size of destination buffer.
-
 
166
 */
-
 
167
void strncpy(char *dest, const char *src, size_t len)
-
 
168
{
-
 
169
    unsigned int i;
-
 
170
    for (i = 0; i < len; i++) {
-
 
171
        if (!(dest[i] = src[i]))
-
 
172
            return;
-
 
173
    }
-
 
174
    dest[i-1] = '\0';
-
 
175
}
-
 
176
 
-
 
177
/** Convert ascii representation to unative_t
80
/** Convert ascii representation to unative_t
178
 *
81
 *
179
 * Supports 0x for hexa & 0 for octal notation.
82
 * Supports 0x for hexa & 0 for octal notation.
180
 * Does not check for overflows, does not support negative numbers
83
 * Does not check for overflows, does not support negative numbers
181
 *
84
 *