[LinuxBIOS] r518 - in LinuxBIOSv3: arch/x86 include lib

svn at openbios.org svn at openbios.org
Sat Nov 24 23:17:27 CET 2007


Author: uwe
Date: 2007-11-24 23:17:26 +0100 (Sat, 24 Nov 2007)
New Revision: 518

Added:
   LinuxBIOSv3/lib/string.c
Modified:
   LinuxBIOSv3/arch/x86/Makefile
   LinuxBIOSv3/include/string.h
Log:
Move the code from strings.h to a C file. We should really avoid
to have code in header files.

Signed-off-by: Uwe Hermann <uwe at hermann-uwe.de>
Acked-by: Stefan Reinauer <stepan at coresystems.de>



Modified: LinuxBIOSv3/arch/x86/Makefile
===================================================================
--- LinuxBIOSv3/arch/x86/Makefile	2007-11-22 23:43:06 UTC (rev 517)
+++ LinuxBIOSv3/arch/x86/Makefile	2007-11-24 22:17:26 UTC (rev 518)
@@ -107,7 +107,7 @@
 #
 
 STAGE0_LIB_OBJ       = uart8250.o mem.o elfboot.o lar.o delay.o vtxprintf.o \
-		       vsprintf.o console.o $(DECOMPRESSORS)
+		       vsprintf.o console.o string.o $(DECOMPRESSORS)
 STAGE0_ARCH_X86_OBJ  = stage1.o serial.o archelfboot.o speaker.o \
 		       udelay_io.o mc146818rtc.o post_code.o
 
@@ -169,7 +169,8 @@
 # TODO: This should be compressed with the default compressor.
 #
 
-STAGE2_LIB_OBJ       = stage2.o clog2.o mem.o tables.o delay.o compute_ip_checksum.o
+STAGE2_LIB_OBJ       = stage2.o clog2.o mem.o tables.o delay.o \
+		       compute_ip_checksum.o string.o
 
 STAGE2_ARCH_X86_OBJ  = archtables.o linuxbios_table.o udelay_io.o
 STAGE2_ARCH_X86_OBJ += pci_ops_auto.o pci_ops_conf1.o pci_ops_conf2.o

Modified: LinuxBIOSv3/include/string.h
===================================================================
--- LinuxBIOSv3/include/string.h	2007-11-22 23:43:06 UTC (rev 517)
+++ LinuxBIOSv3/include/string.h	2007-11-24 22:17:26 UTC (rev 518)
@@ -23,111 +23,19 @@
 
 #include <types.h>
 
-/* Prototypes for functions from lib/mem.c. */
+/* lib/string.c */
+size_t strnlen(const char *str, size_t maxlen);
+size_t strlen(const char *str);
+int strcmp(const char *s1, const char *s2);
+int strncmp(const char *s1, const char *s2, int maxlen);
+
+/* lib/mem.c */
 void *memcpy(void *dest, const void *src, size_t len);
 void *memmove(void *dest, const void *src, size_t len);
 void *memset(void *s, int c, size_t len);
 int memcmp(const void *s1, const void *s2, size_t len);
 
-/* Prototypes for functions from console/vsprintf.c. */
+/* console/vsprintf.c */
 int sprintf(char *buf, const char *fmt, ...);
 
-/**
- * Calculate the length of a fixed-size string.
- *
- * @param str The input string.
- * @param maxlen Return at most maxlen characters as length of the string.
- * @return The length of the string, not including the final NUL character.
- * 	   The maximum length returned is maxlen.
- */
-static inline size_t strnlen(const char *str, size_t maxlen)
-{
-	size_t len = 0;
-
-	/* NULL and empty strings have length 0. */
-	if (!str)
-		return 0;
-
-	/* Loop until we find a NUL character, or maxlen is reached. */
-	while ((*str++ != '\0') && (len < maxlen))
-		len++;
-
-	return len;
-}
-
-/**
- * Calculate the length of a string.
- *
- * @param str The input string.
- * @return The length of the string, not including the final NUL character.
- */
-static inline size_t strlen(const char *str)
-{
-	size_t len = 0;
-
-	/* NULL and empty strings have length 0. */
-	if (!str)
-		return 0;
-
-	/* Loop until we find a NUL character. */
-	while (*str++ != '\0')
-		len++;
-
-	return len;
-}
-
-/**
- * Compare two strings.
- *
- * @param s1 The first string.
- * @param s2 The second string.
- * @return Returns a value less than zero, if s1 is shorter than s2. Returns
- * 	   zero, if s1 equals s2. Returns a value greater than zero, if
- * 	   s1 is longer than s2.
- */
-static inline int strcmp(const char *s1, const char *s2)
-{
-	char c1, c2;
-
-	/* Set c1 == c2, so that we can enter the while loop. */
-	c1 = 0;
-	c2 = 0;
-
-	/* Compare characters until they differ, or one of the strings ends. */
-	while (c1 == c2) {
-		/* Read the next character from each string. */
-		c1 = *s1++;
-		c2 = *s2++;
-
-		/* Return something negative (if s1 is shorter than s2), or
-		   zero (if s1 equals s2). */
-		if (c1 == '\0')
-			return c1 - c2;
-	}
-
-	/* Return someting positive (if s1 is longer than s2), or zero (if s1
-	   and s2 are equal). */
-	return c1 - c2;
-}
-
-/**
- * Compare two strings with fixed length.
- *
- * @param s1 The first string.
- * @param s2 The second string.
- * @param maxlen Return at most maxlen characters as length of the string.
- * @return A non-zero value if s1 and s2 differ, or zero if s1 equals s2.
- */
-static inline int strncmp(const char *s1, const char *s2, int maxlen)
-{
-	int i;
-
-	for (i = 0; i < maxlen; i++) {
-		if (s1[i] != s2[i])
-			return s1[i] - s2[i];
-	}
-
-	return 0;
-}
-
 #endif				/* STRING_H */

Added: LinuxBIOSv3/lib/string.c
===================================================================
--- LinuxBIOSv3/lib/string.c	                        (rev 0)
+++ LinuxBIOSv3/lib/string.c	2007-11-24 22:17:26 UTC (rev 518)
@@ -0,0 +1,119 @@
+/*
+ * This file is part of the LinuxBIOS project.
+ *
+ * Copyright (C) 2007 Uwe Hermann <uwe at hermann-uwe.de>
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <types.h>
+
+/**
+ * Calculate the length of a fixed-size string.
+ *
+ * @param str The input string.
+ * @param maxlen Return at most maxlen characters as length of the string.
+ * @return The length of the string, not including the final NUL character.
+ * 	   The maximum length returned is maxlen.
+ */
+size_t strnlen(const char *str, size_t maxlen)
+{
+	size_t len = 0;
+
+	/* NULL and empty strings have length 0. */
+	if (!str)
+		return 0;
+
+	/* Loop until we find a NUL character, or maxlen is reached. */
+	while ((*str++ != '\0') && (len < maxlen))
+		len++;
+
+	return len;
+}
+
+/**
+ * Calculate the length of a string.
+ *
+ * @param str The input string.
+ * @return The length of the string, not including the final NUL character.
+ */
+size_t strlen(const char *str)
+{
+	size_t len = 0;
+
+	/* NULL and empty strings have length 0. */
+	if (!str)
+		return 0;
+
+	/* Loop until we find a NUL character. */
+	while (*str++ != '\0')
+		len++;
+
+	return len;
+}
+
+/**
+ * Compare two strings.
+ *
+ * @param s1 The first string.
+ * @param s2 The second string.
+ * @return Returns a value less than zero, if s1 is shorter than s2. Returns
+ * 	   zero, if s1 equals s2. Returns a value greater than zero, if
+ * 	   s1 is longer than s2.
+ */
+int strcmp(const char *s1, const char *s2)
+{
+	char c1, c2;
+
+	/* Set c1 == c2, so that we can enter the while loop. */
+	c1 = 0;
+	c2 = 0;
+
+	/* Compare characters until they differ, or one of the strings ends. */
+	while (c1 == c2) {
+		/* Read the next character from each string. */
+		c1 = *s1++;
+		c2 = *s2++;
+
+		/* Return something negative (if s1 is shorter than s2), or
+		   zero (if s1 equals s2). */
+		if (c1 == '\0')
+			return c1 - c2;
+	}
+
+	/* Return someting positive (if s1 is longer than s2), or zero (if s1
+	   and s2 are equal). */
+	return c1 - c2;
+}
+
+/**
+ * Compare two strings with fixed length.
+ *
+ * @param s1 The first string.
+ * @param s2 The second string.
+ * @param maxlen Return at most maxlen characters as length of the string.
+ * @return A non-zero value if s1 and s2 differ, or zero if s1 equals s2.
+ */
+int strncmp(const char *s1, const char *s2, int maxlen)
+{
+	int i;
+
+	for (i = 0; i < maxlen; i++) {
+		if (s1[i] != s2[i])
+			return s1[i] - s2[i];
+	}
+
+	return 0;
+}





More information about the coreboot mailing list