summaryrefslogtreecommitdiffstats
path: root/src/include/string.h
diff options
context:
space:
mode:
authorMichael Brown2015-02-16 18:59:11 +0100
committerMichael Brown2015-02-17 00:16:20 +0100
commit8ee39f7432e63c2382ab3e7d24e234310f4532c9 (patch)
tree9261fe919a505f8f5d98e288f68ac99a6fd62c3c /src/include/string.h
parent[libc] Remove unused string functions (diff)
downloadipxe-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/string.h')
-rw-r--r--src/include/string.h77
1 files changed, 42 insertions, 35 deletions
diff --git a/src/include/string.h b/src/include/string.h
index dfd78a69..59696dd8 100644
--- a/src/include/string.h
+++ b/src/include/string.h
@@ -1,46 +1,53 @@
-/*
- * Copyright (C) 1991, 1992 Linus Torvalds
- * Copyright (C) 2004 Tobias Lorenz
+#ifndef _STRING_H
+#define _STRING_H
+
+/** @file
*
- * string handling functions
- * based on linux/include/linux/ctype.h
- * and linux/include/linux/string.h
+ * String functions
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
*/
-FILE_LICENCE ( GPL2_ONLY );
-
-#ifndef ETHERBOOT_STRING_H
-#define ETHERBOOT_STRING_H
+FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h>
#include <bits/string.h>
-char * strcpy(char * dest,const char *src) __nonnull;
-char * strncpy(char * dest,const char *src,size_t count) __nonnull;
-char * strcat(char * dest, const char * src) __nonnull;
-int __pure strcmp(const char * cs,const char * ct) __nonnull;
-int __pure strncmp(const char * cs,const char * ct,
- size_t count) __nonnull;
-char * __pure strchr(const char * s, int c) __nonnull;
-char * __pure strrchr(const char * s, int c) __nonnull;
-size_t __pure strlen(const char * s) __nonnull;
-size_t __pure strnlen(const char * s, size_t count) __nonnull;
-char * __pure strpbrk(const char * cs,const char * ct) __nonnull;
-char * strsep(char **s, const char *ct) __nonnull;
-void * memset(void * s,int c,size_t count) __nonnull;
+/* Architecture-specific code is expected to provide these functions,
+ * but may instead explicitly choose to use the generic versions.
+ */
+void * memset ( void *dest, int character, size_t len ) __nonnull;
void * memcpy ( void *dest, const void *src, size_t len ) __nonnull;
-void * memmove(void * dest,const void *src,size_t count) __nonnull;
-int __pure memcmp(const void * cs,const void * ct,
- size_t count) __nonnull;
-char * __pure strstr(const char * s1,const char * s2) __nonnull;
-void * __pure memchr(const void *s, int c, size_t n) __nonnull;
-char * __malloc strdup(const char *s) __nonnull;
-char * __malloc strndup(const char *s, size_t n) __nonnull;
+void * memmove ( void *dest, const void *src, size_t len ) __nonnull;
+extern void * generic_memset ( void *dest, int character,
+ size_t len ) __nonnull;
+extern void * generic_memcpy ( void *dest, const void *src,
+ size_t len ) __nonnull;
+extern void * generic_memmove ( void *dest, const void *src,
+ size_t len ) __nonnull;
+
+extern int __pure memcmp ( const void *first, const void *second,
+ size_t len ) __nonnull;
+extern void * __pure memchr ( const void *src, int character,
+ size_t len ) __nonnull;
+extern void * memswap ( void *dest, void *src, size_t len ) __nonnull;
+extern int __pure strcmp ( const char *first, const char *second ) __nonnull;
+extern int __pure strncmp ( const char *first, const char *second,
+ size_t max ) __nonnull;
+extern size_t __pure strlen ( const char *src ) __nonnull;
+extern size_t __pure strnlen ( const char *src, size_t max ) __nonnull;
+extern char * __pure strchr ( const char *src, int character ) __nonnull;
+extern char * __pure strrchr ( const char *src, int character ) __nonnull;
+extern char * __pure strstr ( const char *haystack,
+ const char *needle ) __nonnull;
+extern char * strcpy ( char *dest, const char *src ) __nonnull;
+extern char * strncpy ( char *dest, const char *src, size_t max ) __nonnull;
+extern char * strcat ( char *dest, const char *src ) __nonnull;
+extern char * __malloc strdup ( const char *src ) __nonnull;
+extern char * __malloc strndup ( const char *src, size_t max ) __nonnull;
+extern char * __pure strpbrk ( const char *string,
+ const char *delim ) __nonnull;
+extern char * strsep ( char **string, const char *delim ) __nonnull;
-extern const char * __pure strerror ( int errno );
+extern char * __pure strerror ( int errno );
-#endif /* ETHERBOOT_STRING */
+#endif /* _STRING_H */