All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Hatle <mark.hatle@kernel.crashing.org>
To: yocto-patches@lists.yoctoproject.org
Cc: skandigraun@gmail.com, landervanloock@gmail.com,
	richard.purdie@linuxfoundation.org, fntoth@gmail.com
Subject: [pseudo][PATCH v3 1/3] Move ftw and ftw64 to calling ntfw and nftw64
Date: Sat,  3 May 2025 14:59:53 -0500	[thread overview]
Message-ID: <1746302395-8723-2-git-send-email-mark.hatle@kernel.crashing.org> (raw)
In-Reply-To: <1746302395-8723-1-git-send-email-mark.hatle@kernel.crashing.org>

From: Mark Hatle <mark.hatle@amd.com>

The 4 functions are very similar to each other: nftw-nftw64 and ftw-ftw64 are
identical to their pair, except for the stat struct they use (stat vs stat64).

nftw is a "superset" of ftw: nftw is backwards compatible with ftw, but it
also accepts a number of extra flags to modify its behavior.

Since all the 4 functions are so similar, the same codebase is used to
implement all (which is also fairly similar to their implementation in
glibc).

[1]: https://linux.die.net/man/3/nftw

Re-implemented, but based on the ideas from Gyorgy Sarvari <skandigraun@gmail.com>

Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
 guts/README              |  4 ++--
 ports/linux/guts/ftw64.c |  9 ++++++++-
 ports/unix/guts/ftw.c    | 10 +++++++++-
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/guts/README b/guts/README
index 0a1fe5f..bb2e573 100644
--- a/guts/README
+++ b/guts/README
@@ -54,6 +54,8 @@ other functions:
 	__xmknod:		__xmknodat
 	__xstat64:		__fxstatat64
 	__xstat:		__fxstatat
+	ftw:			nftw
+	ftw64:			nftw64
 
 The following functions are full implementations:
 
@@ -129,8 +131,6 @@ calling the underlying routine.
 	eaccess
 	euidaccess
 	fts_open
-	ftw64
-	ftw
 	glob64
 	glob
 	lutimes
diff --git a/ports/linux/guts/ftw64.c b/ports/linux/guts/ftw64.c
index 48adb80..72e80f1 100644
--- a/ports/linux/guts/ftw64.c
+++ b/ports/linux/guts/ftw64.c
@@ -9,7 +9,14 @@
  *	int rc = -1;
  */
 
-	rc = real_ftw64(path, fn, nopenfd);
+	// 1. Set the flag argument to 0, just like glibc does.
+	// 2. The difference between ftw and nftw callback
+	//    is only the last parameter: struct FTW is only used
+	//    by nftw(), and it is missing from ftw().
+	//    However since otherwise the stacklayout for the
+	//    functions is the same, this cast should work just the
+	//    way we want it. This is also borrowed from glibc.
+	rc = wrap_nftw64(path, (void *)fn, nopenfd, 0);
 
 /*	return rc;
  * }
diff --git a/ports/unix/guts/ftw.c b/ports/unix/guts/ftw.c
index 58945a1..12a17f4 100644
--- a/ports/unix/guts/ftw.c
+++ b/ports/unix/guts/ftw.c
@@ -9,7 +9,15 @@
  *	int rc = -1;
  */
 
-	rc = real_ftw(path, fn, nopenfd);
+	// 1. Set the flag argument to 0, just like glibc does.
+	// 2. The difference between ftw and nftw callback
+	//    is only the last parameter: struct FTW is only used
+	//    by nftw(), and it is missing from ftw().
+	//    However since otherwise the stacklayout for the
+	//    functions is the same, this cast should work just the
+	//    way we want it. This is also borrowed from glibc.
+
+	rc = wrap_nftw(path, (void *)fn, nopenfd, 0);
 
 /*	return rc;
  * }
-- 
2.34.1



  reply	other threads:[~2025-05-03 20:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-03 19:59 [pseudo][PATCH v3 0/3] nftw, ftw: add wrappers Mark Hatle
2025-05-03 19:59 ` Mark Hatle [this message]
2025-05-03 19:59 ` [pseudo][PATCH v3 2/3] nftw, nftw64: add wrapper Mark Hatle
2025-05-04 13:48   ` Gyorgy Sarvari
2025-05-03 19:59 ` [pseudo][PATCH v3 3/3] ftw, nftw, ftw64 and nftw64: add tests Mark Hatle
2025-05-04 16:21 ` [pseudo][PATCH v3 0/3] nftw, ftw: add wrappers Richard Purdie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1746302395-8723-2-git-send-email-mark.hatle@kernel.crashing.org \
    --to=mark.hatle@kernel.crashing.org \
    --cc=fntoth@gmail.com \
    --cc=landervanloock@gmail.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=skandigraun@gmail.com \
    --cc=yocto-patches@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.