PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/powerpc/boot/stdlib.c

http://github.com/mirrors/linux
C | 42 lines | 25 code | 8 blank | 9 comment | 12 complexity | eaeded2148f3372d0c1b9d208f7c63c1 MD5 | raw file
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * stdlib functions
 4 *
 5 * Author: Scott Wood <scottwood@freescale.com>
 6 *
 7 * Copyright (c) 2007 Freescale Semiconductor, Inc.
 8 */
 9
10#include "stdlib.h"
11
12/* Not currently supported: leading whitespace, sign, 0x prefix, zero base */
13unsigned long long int strtoull(const char *ptr, char **end, int base)
14{
15	unsigned long long ret = 0;
16
17	if (base > 36)
18		goto out;
19
20	while (*ptr) {
21		int digit;
22
23		if (*ptr >= '0' && *ptr <= '9' && *ptr < '0' + base)
24			digit = *ptr - '0';
25		else if (*ptr >= 'A' && *ptr < 'A' + base - 10)
26			digit = *ptr - 'A' + 10;
27		else if (*ptr >= 'a' && *ptr < 'a' + base - 10)
28			digit = *ptr - 'a' + 10;
29		else
30			break;
31
32		ret *= base;
33		ret += digit;
34		ptr++;
35	}
36
37out:
38	if (end)
39		*end = (char *)ptr;
40
41	return ret;
42}