mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-16 16:54:20 +08:00
ce0aa5dd20
Make the boot code also accept the console=uart8250,io,0x2f8,115200n form of early console. Also add back simple_guess_base(), otherwise those simple_strtoull(,,0) are not going to work. Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <4C3CCE05.4090505@kernel.org> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
114 lines
2.1 KiB
C
114 lines
2.1 KiB
C
/* -*- linux-c -*- ------------------------------------------------------- *
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
* Copyright 2007 rPath, Inc. - All Rights Reserved
|
|
*
|
|
* This file is part of the Linux kernel, and is made available under
|
|
* the terms of the GNU General Public License version 2.
|
|
*
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
/*
|
|
* Very basic string functions
|
|
*/
|
|
|
|
#include "boot.h"
|
|
|
|
int strcmp(const char *str1, const char *str2)
|
|
{
|
|
const unsigned char *s1 = (const unsigned char *)str1;
|
|
const unsigned char *s2 = (const unsigned char *)str2;
|
|
int delta = 0;
|
|
|
|
while (*s1 || *s2) {
|
|
delta = *s2 - *s1;
|
|
if (delta)
|
|
return delta;
|
|
s1++;
|
|
s2++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int strncmp(const char *cs, const char *ct, size_t count)
|
|
{
|
|
unsigned char c1, c2;
|
|
|
|
while (count) {
|
|
c1 = *cs++;
|
|
c2 = *ct++;
|
|
if (c1 != c2)
|
|
return c1 < c2 ? -1 : 1;
|
|
if (!c1)
|
|
break;
|
|
count--;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
size_t strnlen(const char *s, size_t maxlen)
|
|
{
|
|
const char *es = s;
|
|
while (*es && maxlen) {
|
|
es++;
|
|
maxlen--;
|
|
}
|
|
|
|
return (es - s);
|
|
}
|
|
|
|
unsigned int atou(const char *s)
|
|
{
|
|
unsigned int i = 0;
|
|
while (isdigit(*s))
|
|
i = i * 10 + (*s++ - '0');
|
|
return i;
|
|
}
|
|
|
|
/* Works only for digits and letters, but small and fast */
|
|
#define TOLOWER(x) ((x) | 0x20)
|
|
|
|
static unsigned int simple_guess_base(const char *cp)
|
|
{
|
|
if (cp[0] == '0') {
|
|
if (TOLOWER(cp[1]) == 'x' && isxdigit(cp[2]))
|
|
return 16;
|
|
else
|
|
return 8;
|
|
} else {
|
|
return 10;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* simple_strtoull - convert a string to an unsigned long long
|
|
* @cp: The start of the string
|
|
* @endp: A pointer to the end of the parsed string will be placed here
|
|
* @base: The number base to use
|
|
*/
|
|
|
|
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
|
|
{
|
|
unsigned long long result = 0;
|
|
|
|
if (!base)
|
|
base = simple_guess_base(cp);
|
|
|
|
if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x')
|
|
cp += 2;
|
|
|
|
while (isxdigit(*cp)) {
|
|
unsigned int value;
|
|
|
|
value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10;
|
|
if (value >= base)
|
|
break;
|
|
result = result * base + value;
|
|
cp++;
|
|
}
|
|
if (endp)
|
|
*endp = (char *)cp;
|
|
|
|
return result;
|
|
}
|