cregit-Linux how code gets into the kernel

Release 4.14 arch/x86/boot/string.c

Directory: arch/x86/boot
/* -*- 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 <linux/types.h>
#include "ctype.h"
#include "string.h"

/*
 * Undef these macros so that the functions that we provide
 * here will have the correct names regardless of how string.h
 * may have chosen to #define them.
 */

#undef memcpy

#undef memset

#undef memcmp


int memcmp(const void *s1, const void *s2, size_t len) { bool diff; asm("repe; cmpsb; setnz %0" : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); return diff; }

Contributors

PersonTokensPropCommitsCommitProp
Vivek Goyal2496.00%150.00%
H. Peter Anvin14.00%150.00%
Total25100.00%2100.00%


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 = *s1 - *s2; if (delta) return delta; s1++; s2++; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
H. Peter Anvin8097.56%150.00%
Arjun Sreedharan22.44%150.00%
Total82100.00%2100.00%


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; }

Contributors

PersonTokensPropCommitsCommitProp
Pekka J Enberg70100.00%1100.00%
Total70100.00%1100.00%


size_t strnlen(const char *s, size_t maxlen) { const char *es = s; while (*es && maxlen) { es++; maxlen--; } return (es - s); }

Contributors

PersonTokensPropCommitsCommitProp
H. Peter Anvin42100.00%1100.00%
Total42100.00%1100.00%


unsigned int atou(const char *s) { unsigned int i = 0; while (isdigit(*s)) i = i * 10 + (*s++ - '0'); return i; }

Contributors

PersonTokensPropCommitsCommitProp
H. Peter Anvin42100.00%1100.00%
Total42100.00%1100.00%

/* 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; } }

Contributors

PersonTokensPropCommitsCommitProp
Yinghai Lu56100.00%1100.00%
Total56100.00%1100.00%

/** * 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; }

Contributors

PersonTokensPropCommitsCommitProp
Pekka J Enberg12691.30%150.00%
Yinghai Lu128.70%150.00%
Total138100.00%2100.00%


long simple_strtol(const char *cp, char **endp, unsigned int base) { if (*cp == '-') return -simple_strtoull(cp + 1, endp, base); return simple_strtoull(cp, endp, base); }

Contributors

PersonTokensPropCommitsCommitProp
Baoquan He49100.00%1100.00%
Total49100.00%1100.00%

/** * strlen - Find the length of a string * @s: The string to be sized */
size_t strlen(const char *s) { const char *sc; for (sc = s; *sc != '\0'; ++sc) /* nothing */; return sc - s; }

Contributors

PersonTokensPropCommitsCommitProp
Matt Fleming36100.00%1100.00%
Total36100.00%1100.00%

/** * strstr - Find the first substring in a %NUL terminated string * @s1: The string to be searched * @s2: The string to search for */
char *strstr(const char *s1, const char *s2) { size_t l1, l2; l2 = strlen(s2); if (!l2) return (char *)s1; l1 = strlen(s1); while (l1 >= l2) { l1--; if (!memcmp(s1, s2, l2)) return (char *)s1; s1++; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Matt Fleming83100.00%1100.00%
Total83100.00%1100.00%

/** * strchr - Find the first occurrence of the character c in the string s. * @s: the string to be searched * @c: the character to search for */
char *strchr(const char *s, int c) { while (*s != (char)c) if (*s++ == '\0') return NULL; return (char *)s; }

Contributors

PersonTokensPropCommitsCommitProp
Dave Jiang42100.00%1100.00%
Total42100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Pekka J Enberg20429.23%17.69%
H. Peter Anvin16824.07%215.38%
Matt Fleming12117.34%17.69%
Yinghai Lu699.89%17.69%
Baoquan He497.02%17.69%
Dave Jiang436.16%17.69%
Vivek Goyal284.01%215.38%
Michael Davidson101.43%17.69%
Nicholas Mc Guire30.43%17.69%
Arjun Sreedharan20.29%17.69%
Américo Wang10.14%17.69%
Total698100.00%13100.00%
Directory: arch/x86/boot
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.