Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions newlib/libc/posix/ftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@

#include <ftw.h>

/* 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 */
4 changes: 2 additions & 2 deletions newlib/libc/posix/glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Loading