diff options
author | Michael Brown | 2015-02-16 18:59:11 +0100 |
---|---|---|
committer | Michael Brown | 2015-02-17 00:16:20 +0100 |
commit | 8ee39f7432e63c2382ab3e7d24e234310f4532c9 (patch) | |
tree | 9261fe919a505f8f5d98e288f68ac99a6fd62c3c /src/include/strings.h | |
parent | [libc] Remove unused string functions (diff) | |
download | ipxe-8ee39f7432e63c2382ab3e7d24e234310f4532c9.tar.gz ipxe-8ee39f7432e63c2382ab3e7d24e234310f4532c9.tar.xz ipxe-8ee39f7432e63c2382ab3e7d24e234310f4532c9.zip |
[libc] Rewrite string functions
Some of the C library string functions have an unknown provenance.
Reimplement all such functions to avoid potential licensing
uncertainty.
Remove the inline-assembler versions of strlen(), memswap(), and
strncmp(); these save a minimal amount of space (around 40 bytes in
total) and are not performance-critical.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/strings.h')
-rw-r--r-- | src/include/strings.h | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/include/strings.h b/src/include/strings.h index 6912a1e4..8b57a40a 100644 --- a/src/include/strings.h +++ b/src/include/strings.h @@ -1,12 +1,23 @@ #ifndef _STRINGS_H #define _STRINGS_H +/** @file + * + * String functions + * + */ + FILE_LICENCE ( GPL2_OR_LATER ); -#include <limits.h> #include <string.h> #include <bits/strings.h> +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ static inline __attribute__ (( always_inline )) int __constant_flsll ( unsigned long long x ) { int r = 0; @@ -41,6 +52,12 @@ __constant_flsll ( unsigned long long x ) { return r; } +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ static inline __attribute__ (( always_inline )) int __constant_flsl ( unsigned long x ) { return __constant_flsll ( x ); @@ -49,24 +66,55 @@ __constant_flsl ( unsigned long x ) { int __flsll ( long long x ); int __flsl ( long x ); +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define flsll( x ) \ ( __builtin_constant_p ( x ) ? __constant_flsll ( x ) : __flsll ( x ) ) +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define flsl( x ) \ ( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) ) +/** + * Find last (i.e. most significant) set bit + * + * @v x Value + * @ret msb Most significant bit set in value (LSB=1), or zero + */ #define fls( x ) flsl ( x ) -extern int strcasecmp ( const char *s1, const char *s2 ); - +/** + * Copy memory + * + * @v src Source + * @v dest Destination + * @v len Length + */ static inline __attribute__ (( always_inline )) void -bcopy ( const void *src, void *dest, size_t n ) { - memmove ( dest, src, n ); +bcopy ( const void *src, void *dest, size_t len ) { + memmove ( dest, src, len ); } +/** + * Zero memory + * + * @v dest Destination + * @v len Length + */ static inline __attribute__ (( always_inline )) void -bzero ( void *s, size_t n ) { - memset ( s, 0, n ); +bzero ( void *dest, size_t len ) { + memset ( dest, 0, len ); } +int __pure strcasecmp ( const char *first, const char *second ) __nonnull; + #endif /* _STRINGS_H */ |