diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -57,6 +57,7 @@ creat_f c_exec; creat_f c_flags; creat_f c_follow; +creat_f c_fprint; creat_f c_fstype; creat_f c_group; creat_f c_ignore_readdir_race; @@ -92,6 +93,8 @@ exec_f f_expr; exec_f f_false; exec_f f_flags; +exec_f f_fprint; +exec_f f_fprint0; exec_f f_fstype; exec_f f_group; exec_f f_inum; diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -135,6 +135,7 @@ char *_a_data[2]; /* array of char pointers */ char *_c_data; /* char pointer */ regex_t *_re_data; /* regex */ + FILE *_fprint_file; /* file stream for -fprint */ } p_un; } PLAN; #define a_data p_un._a_data @@ -162,6 +163,7 @@ #define e_pbsize p_un.ex._e_pbsize #define e_psizemax p_un.ex._e_psizemax #define e_next p_un.ex._e_next +#define fprint_file p_un._fprint_file typedef struct _option { const char *name; /* option name */ diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1 --- a/usr.bin/find/find.1 +++ b/usr.bin/find/find.1 @@ -493,6 +493,28 @@ .Ar flags bits match those of .Ar notflags . +.It Ic -fprint Ar filename +This primary always evaluates to true. +This creates +.Ar filename +or truncates the file if it already exists. +The file is created at startup. +It writes the pathname of the current file to this file, followed +by a newline character. +The file will be empty if no files are matched. +.Pp +.It Ic -fprint0 Ar filename +This primary always evaluates to true. +This creates +.Ar filename +or truncates the file if it already exists. +The file is created at startup. +It writes the pathname of the current file to this file, followed +by an ASCII +.Dv NUL +character (character code 0). +The file will be empty if no files are matched. +.Pp .It Ic -fstype Ar type True if the file is contained in a file system of type .Ar type . diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -866,6 +866,49 @@ return palloc(option); } +/* + * -fprint functions -- + * + * Always true, causes the current pathname to be written to + * specified file followed by a newline + */ +int +f_fprint(PLAN *plan, FTSENT *entry) +{ + fprintf(plan->fprint_file, "%s\n", entry->fts_path); + return 1; +} + +PLAN * +c_fprint(OPTION *option, char ***argvp) +{ + PLAN *new; + char *fn; + + isoutput = 1; + + new = palloc(option); + fn = nextarg(option, argvp); + new->fprint_file = fopen(fn, "w"); + if (new->fprint_file == NULL) + err(1, "fprint: cannot create %s", fn); + + return (new); +} + +/* + * -fprint0 functions -- + * + * Always true, causes the current pathname to be written to + * specified file followed by a NUL + */ +int +f_fprint0(PLAN *plan, FTSENT *entry) +{ + fprintf(plan->fprint_file, "%s%c", entry->fts_path, '\0'); + return 1; +} + #if HAVE_STRUCT_STATFS_F_FSTYPENAME /* * -fstype functions -- diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -81,8 +81,8 @@ #endif // -fls { "-follow", c_follow, f_always_true, 0 }, -// -fprint -// -fprint0 + { "-fprint", c_fprint, f_fprint, 0 }, + { "-fprint0", c_fprint, f_fprint0, 0 }, // -fprintf #if HAVE_STRUCT_STATFS_F_FSTYPENAME { "-fstype", c_fstype, f_fstype, 0 },