From: Theodore Ts'o Date: Sun, 25 Mar 2018 02:26:24 +0000 (-0400) Subject: libext2fs: support operating systems that don't have strnlen() X-Git-Tag: v1.44.1~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51ed02bec92431d032d3e5eb0b4b234eef97abc6;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c index 13bca6e99..7f78c5f75 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) {