lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/lib/string.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * stupid library routines.. The optimized versions should generally be found |
| 9 | * as inline code in <asm-xx/string.h> |
| 10 | * |
| 11 | * These are buggy as well.. |
| 12 | * |
| 13 | * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de> |
| 14 | * - Added strsep() which will replace strtok() soon (because strsep() is |
| 15 | * reentrant and should be faster). Use only strsep() in new code, please. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <asm/string.h> |
| 20 | //#include <malloc.h> |
| 21 | |
| 22 | |
| 23 | /* |
| 24 | ****************************************************************************** |
| 25 | * Function: |
| 26 | * Description: |
| 27 | * Parameters: |
| 28 | * Input: |
| 29 | * Output: |
| 30 | * Returns: |
| 31 | * Others: |
| 32 | ******************************************************************************* |
| 33 | */ |
| 34 | uint32_t strlen( uint8_t* s ) |
| 35 | { |
| 36 | uint8_t *sc; |
| 37 | |
| 38 | for (sc = s; *sc != '\0'; ++sc) |
| 39 | /* nothing */; |
| 40 | return sc - s; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | ****************************************************************************** |
| 45 | * Function: |
| 46 | * Description: |
| 47 | * Parameters: |
| 48 | * Input: |
| 49 | * Output: |
| 50 | * Returns: |
| 51 | * Others: |
| 52 | ******************************************************************************* |
| 53 | */ |
| 54 | void * memset(void * s,int c,size_t count) |
| 55 | { |
| 56 | unsigned long *sl = (unsigned long *) s; |
| 57 | unsigned long cl = 0; |
| 58 | char *s8; |
| 59 | int i; |
| 60 | |
| 61 | /* do it one word at a time (32 bits or 64 bits) while possible */ |
| 62 | if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) { |
| 63 | for (i = 0; i < sizeof(*sl); i++) { |
| 64 | cl <<= 8; |
| 65 | cl |= c & 0xff; |
| 66 | } |
| 67 | while (count >= sizeof(*sl)) { |
| 68 | *sl++ = cl; |
| 69 | count -= sizeof(*sl); |
| 70 | } |
| 71 | } |
| 72 | /* fill 8 bits at a time */ |
| 73 | s8 = (char *)sl; |
| 74 | while (count--) |
| 75 | *s8++ = c; |
| 76 | |
| 77 | return s; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | ****************************************************************************** |
| 82 | * Function: |
| 83 | * Description: |
| 84 | * Parameters: |
| 85 | * Input: |
| 86 | * Output: |
| 87 | * Returns: |
| 88 | * Others: |
| 89 | ******************************************************************************* |
| 90 | */ |
| 91 | int memcmp(void *a, void *c, int n) |
| 92 | { |
| 93 | int i; |
| 94 | for (i = 0; i < n; i++) { |
| 95 | if (((unsigned char *)c)[i] != ((unsigned char *)a)[i]) |
| 96 | return 1; |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | ****************************************************************************** |
| 103 | * Function: |
| 104 | * Description: |
| 105 | * Parameters: |
| 106 | * Input: |
| 107 | * Output: |
| 108 | * Returns: |
| 109 | * Others: |
| 110 | ******************************************************************************* |
| 111 | */ |
| 112 | void memcpy( uint32_t dest, uint32_t src, uint32_t count ) |
| 113 | { |
| 114 | char *tmp = (char *) dest, *s = (char *) src; |
| 115 | |
| 116 | while (count--) |
| 117 | *tmp++ = *s++; |
| 118 | } |
| 119 | |
| 120 | |