From b1c6185a40f7a40381ab78b97f6715b09f84a9e4 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 22 Feb 2025 13:14:51 +0100 Subject: [PATCH] find: Implement -print0 --- find.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/find.c b/find.c index 052c0e2..8fc1542 100644 --- a/find.c +++ b/find.c @@ -133,6 +133,7 @@ static int pri_mtime (struct arg *arg); static int pri_exec (struct arg *arg); static int pri_ok (struct arg *arg); static int pri_print (struct arg *arg); +static int pri_print0 (struct arg *arg); static int pri_newer (struct arg *arg); static int pri_depth (struct arg *arg); @@ -191,6 +192,7 @@ static struct pri_info primaries[] = { { "-exec" , pri_exec , get_exec_arg , free_exec_arg, 1 }, { "-ok" , pri_ok , get_ok_arg , free_ok_arg , 1 }, { "-print" , pri_print , get_print_arg, NULL , 0 }, + { "-print0" , pri_print0 , get_print_arg, NULL , 0 }, { "-newer" , pri_newer , get_newer_arg, NULL , 1 }, { "-depth" , pri_depth , get_depth_arg, NULL , 0 }, @@ -474,6 +476,14 @@ pri_print(struct arg *arg) return 1; } +static int +pri_print0(struct arg *arg) +{ + if (fwrite(arg->path, strlen(arg->path) + 1, 1, stdout) != 1) + eprintf("fwrite failed:"); + return 1; +} + /* FIXME: ignoring nanoseconds */ static int pri_newer(struct arg *arg)