diff --git a/newlib/libc/posix/ftw.c b/newlib/libc/posix/ftw.c index 79e63582ce..ab88fd6f4c 100644 --- a/newlib/libc/posix/ftw.c +++ b/newlib/libc/posix/ftw.c @@ -25,12 +25,18 @@ #include +/* Static callback pointer to maintain the ftw callback between calls */ +static int (*ftw_callback)(const char *, const struct stat *, int); + +static int ftw_wrapper(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) +{ + return ftw_callback(fpath, sb, typeflag); +} + int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit) { - /* The following cast assumes that calling a function with one - * argument more than it needs behaves as expected. This is - * actually undefined, but works on all real-world machines. */ - return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS); + ftw_callback = fn; + return nftw(path, ftw_wrapper, fd_limit, FTW_PHYS); } #endif /* ! HAVE_OPENDIR */ diff --git a/newlib/libc/posix/glob.c b/newlib/libc/posix/glob.c index 20eec0263b..7dc3cbbe11 100644 --- a/newlib/libc/posix/glob.c +++ b/newlib/libc/posix/glob.c @@ -620,7 +620,7 @@ glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit) * and dirent.h as taking pointers to differently typed opaque * structures. */ - struct dirent *(*readdirfunc)(); + struct dirent *(*readdirfunc)(void *); if (pathend > pathend_last) return (1); @@ -645,7 +645,7 @@ glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit) if (pglob->gl_flags & GLOB_ALTDIRFUNC) readdirfunc = pglob->gl_readdir; else - readdirfunc = readdir; + readdirfunc = (struct dirent *(*)(void *))readdir; while ((dp = (*readdirfunc)(dirp))) { u_char *sc; Char *dc;