Subversion Repositories HelenOS-historic

Rev

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

Rev 534 Rev 582
Line 111... Line 111...
111
    for (i = 0; i < len; i++) {
111
    for (i = 0; i < len; i++) {
112
        if (!(dest[i] = src[i]))
112
        if (!(dest[i] = src[i]))
113
            return;
113
            return;
114
    }
114
    }
115
}
115
}
-
 
116
 
-
 
117
/** Convert ascii representation to __native
-
 
118
 *
-
 
119
 * Supports 0x for hexa & 0 for octal notation.
-
 
120
 * Does not check for overflows, does not support negative numbers
-
 
121
 *
-
 
122
 * @param text Textual representation of number
-
 
123
 * @return Converted number or 0 if no valid number ofund
-
 
124
 */
-
 
125
__native atoi(const char *text)
-
 
126
{
-
 
127
    int base = 10;
-
 
128
    __native result = 0;
-
 
129
 
-
 
130
    if (text[0] == '0' && text[1] == 'x') {
-
 
131
        base = 16;
-
 
132
        text += 2;
-
 
133
    } else if (text[0] == '0')
-
 
134
        base = 8;
-
 
135
 
-
 
136
    while (*text) {
-
 
137
        result *= base;
-
 
138
        if (base != 16 && *text >= 'A' && *text <= 'F')
-
 
139
            break;
-
 
140
        if (base == 8 && *text >='8')
-
 
141
            break;
-
 
142
 
-
 
143
        if (*text >= '0' && *text <= '9')
-
 
144
            result += *text - '0';
-
 
145
        else if (*text >= 'A' && *text <= 'F')
-
 
146
            result += *text - 'A' + 10;
-
 
147
        else
-
 
148
            break;
-
 
149
        text++;
-
 
150
    }
-
 
151
 
-
 
152
    return result;
-
 
153
}