summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2015-01-27 18:07:50 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2015-01-27 18:07:50 +0000
commitdc627931848ed6af40be4f7d5bdb8e33d28b8333 (patch)
tree8a458f2a546da385a13b3662586000286e3aa02d
parent0cbd8c2558209432a0f51522cd2adffc59785dd0 (diff)
downloadflashrom-dc627931848ed6af40be4f7d5bdb8e33d28b8333.tar.gz
flashrom-dc627931848ed6af40be4f7d5bdb8e33d28b8333.tar.bz2
flashrom-dc627931848ed6af40be4f7d5bdb8e33d28b8333.zip
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. Corresponding to flashrom svn r1878. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
-rw-r--r--dmi.c17
-rw-r--r--flash.h3
-rw-r--r--helpers.c10
3 files changed, 20 insertions, 10 deletions
diff --git a/dmi.c b/dmi.c
index 832d7abb8..c9d904bd8 100644
--- a/dmi.c
+++ b/dmi.c
@@ -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 @@ static const struct {
};
#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;
diff --git a/flash.h b/flash.h
index 56d9e4bce..5fb743dfe 100644
--- a/flash.h
+++ b/flash.h
@@ -260,6 +260,9 @@ void tolower_string(char *str);
#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[];
diff --git a/helpers.c b/helpers.c
index 5685d299b..7a146c372 100644
--- a/helpers.c
+++ b/helpers.c
@@ -91,3 +91,13 @@ char* strtok_r(char *str, const char *delim, char **nextp)
}
#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