From 51ed02bec92431d032d3e5eb0b4b234eef97abc6 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 24 Mar 2018 22:26:24 -0400 Subject: [PATCH] libext2fs: support operating systems that don't have strnlen() Someone was trying to build e2fsprogs on MacOS 10.6.8, and ran into build problems because MacOS didn't have strnlen() support until seven years ago. Signed-off-by: Theodore Ts'o Reported-by: Jens Bauer --- lib/ext2fs/symlink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c index 13bca6e..7f78c5f 100644 --- a/lib/ext2fs/symlink.c +++ b/lib/ext2fs/symlink.c @@ -28,6 +28,22 @@ #include "ext2_fs.h" #include "ext2fs.h" +#ifndef HAVE_STRNLEN +/* + * Incredibly, libc5 doesn't appear to have strnlen. So we have to + * provide our own. + */ +static int my_strnlen(const char * s, int count) +{ + const char *cp = s; + + while (count-- && *cp) + cp++; + return cp - s; +} +#define strnlen(str, x) my_strnlen((str),(x)) +#endif + errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, const char *name, const char *target) { -- 1.8.3.1