📄 util.c
字号:
/* * This code derived from linux kernel 2.6 * (C) 2005, Some small changes to adopt code to bootloader by Pawel Kolodziejski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "types.h"uint32_t __div64_32(uint64_t *n, uint32_t base) { uint64_t rem = *n; uint64_t b = base; uint64_t res, d = 1; uint32_t high = rem >> 32; /* Reduce the thing a bit first */ res = 0; if (high >= base) { high /= base; res = (uint64_t) high << 32; rem -= (uint64_t) (high*base) << 32; } while ((int64_t)b > 0 && b < rem) { b = b+b; d = d+d; } do { if (rem >= b) { rem -= b; res += d; } b >>= 1; d >>= 1; } while (d); *n = res; return rem;}void __div0(void) { for(;;) { ; }}DItype __lshrdi3(DItype u, word_type b) { DIunion w; word_type bm; DIunion uu; if (b == 0) return u; uu.ll = u; bm = (sizeof(SItype) * BITS_PER_UNIT) - b; if (bm <= 0) { w.s.high = 0; w.s.low = (USItype)uu.s.high >> -bm; } else { USItype carries = (USItype)uu.s.high << bm; w.s.high = (USItype)uu.s.high >> b; w.s.low = ((USItype)uu.s.low >> b) | carries; } return w.ll;}void __clear_cache(char *start, char *end) {}/** * strcpy - Copy a %NUL terminated string * @dest: Where to copy the string to * @src: Where to copy the string from */char * strcpy(char * dest,const char *src){ char *tmp = dest; while ((*dest++ = *src++) != '\0') /* nothing */; return tmp;}/** * 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;}/** * memcpy - Copy one area of memory to another * @dest: Where to copy to * @src: Where to copy from * @count: The size of the area. * * You should not use this function to access IO space, use memcpy_toio() * or memcpy_fromio() instead. */void * memcpy(void * dest,const void *src,size_t count){ char *tmp = (char *) dest, *s = (char *) src; while (count--) *tmp++ = *s++; return dest;}/** * strncpy - Copy a length-limited, %NUL-terminated string * @dest: Where to copy the string to * @src: Where to copy the string from * @count: The maximum number of bytes to copy * * The result is not %NUL-terminated if the source exceeds * @count bytes. * * In the case where the length of @src is less than that of * count, the remainder of @dest will be padded with %NUL. * */char * strncpy(char * dest,const char *src,size_t count){ char *tmp = dest; while (count) { if ((*tmp = *src) != 0) src++; tmp++; count--; } return dest;}/** * strchr - Find the first occurrence of a character in a string * @s: The string to be searched * @c: The character to search for */char * strchr(const char * s, int c){ for(; *s != (char) c; ++s) if (*s == '\0') return NULL; return (char *) s;}/** * strncmp - Compare two length-limited strings * @cs: One string * @ct: Another string * @count: The maximum number of bytes to compare */int strncmp(const char * cs, const char * ct,size_t count){ register signed char __res = 0; while (count) { if ((__res = *cs - *ct++) != 0 || !*cs++) break; count--; } return __res;}/** * memcmp - Compare two areas of memory * @cs: One area of memory * @ct: Another area of memory * @count: The size of the area. */int memcmp(const void * cs,const void * ct,size_t count){ const unsigned char *su1, *su2; int res = 0; for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; return res;}char *strdup(const char *s) { int len; char *p; len = strlen(s) + 1; p = (char *)malloc(len); if (!p) return 0; return memcpy(p, s, len);}int strcmp (const char *s1, const char *s2) { while (*s1 && *s2) { if (*s1 != *s2) return (int)*s1 - (int)*s2; s1++; s2++; } return (int)*s1 - (int)*s2;}int tolower(int c) { if (c >= 'A' && c <= 'Z') return c - 'A' + 'a'; return c;}int isspace(int c) { return (c == '\n' || c == '\r' || c == ' ' || c == '\t');}void *memset(void *s, int c, int n) { unsigned char *p = (unsigned char *)s; while(n--) *p++ = (unsigned char)c; return s;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -