[flashrom] [commit] r1878 - trunk

repository service svn at flashrom.org
Tue Jan 27 19:07:51 CET 2015


Author: stefanct
Date: Tue Jan 27 19:07:50 2015
New Revision: 1878
URL: http://flashrom.org/trac/flashrom/changeset/1878

Log:
Make strnlen() visible in old versions of glibc.

strnlen() is in POSIX 2008 but was a GNU extension up to glibc 2.10
requiring to define _GNU_SOURCE. This fixes compilation on CentOS 4.9.
Also, move our implementation of strnlen() that was added to support
DJGPP to helpers.c.

Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Modified:
   trunk/dmi.c
   trunk/flash.h
   trunk/helpers.c

Modified: trunk/dmi.c
==============================================================================
--- trunk/dmi.c	Mon Jan 26 23:06:04 2015	(r1877)
+++ trunk/dmi.c	Tue Jan 27 19:07:50 2015	(r1878)
@@ -21,6 +21,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+/* strnlen is in POSIX but was a GNU extension up to glibc 2.10 */
+#if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10) || __GLIBC__ < 2
+#define _GNU_SOURCE
+#else
+#define _POSIX_C_SOURCE 200809L
+#endif
+
 #include <strings.h>
 #include <string.h>
 #include <ctype.h>
@@ -86,16 +93,6 @@
 };
 
 #if CONFIG_INTERNAL_DMI == 1
-#ifdef __DJGPP__ /* There is no strnlen in DJGPP. FIXME: Move this to a common utility file. */
-size_t strnlen(const char *str, size_t n)
-{
-	size_t i;
-	for (i = 0; i < n && str[i] != '\0'; i++)
-		;
-	return i;
-}
-#endif
-
 static bool dmi_checksum(const uint8_t * const buf, size_t len)
 {
 	uint8_t sum = 0;

Modified: trunk/flash.h
==============================================================================
--- trunk/flash.h	Mon Jan 26 23:06:04 2015	(r1877)
+++ trunk/flash.h	Tue Jan 27 19:07:50 2015	(r1878)
@@ -260,6 +260,9 @@
 #ifdef __MINGW32__
 char* strtok_r(char *str, const char *delim, char **nextp);
 #endif
+#if defined(__DJGPP__)
+size_t strnlen(const char *str, size_t n);
+#endif
 
 /* flashrom.c */
 extern const char flashrom_version[];

Modified: trunk/helpers.c
==============================================================================
--- trunk/helpers.c	Mon Jan 26 23:06:04 2015	(r1877)
+++ trunk/helpers.c	Tue Jan 27 19:07:50 2015	(r1878)
@@ -91,3 +91,13 @@
 }
 #endif
 
+/* There is no strnlen in DJGPP */
+#if defined(__DJGPP__)
+size_t strnlen(const char *str, size_t n)
+{
+	size_t i;
+	for (i = 0; i < n && str[i] != '\0'; i++)
+		;
+	return i;
+}
+#endif




More information about the flashrom mailing list