1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | --- find/defs.h | 1 + find/parser.c | 22 ++++++++++++++++++++++ find/pred.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ find/tree.c | 1 + 4 files changed, 76 insertions(+)
Index: findutils-4.5.2/find/defs.h =================================================================== --- findutils-4.5.2.orig/find/defs.h +++ findutils-4.5.2/find/defs.h @@ -411,6 +411,7 @@ PREDICATEFUNCTION pred_cnewer; PREDICATEFUNCTION pred_comma; PREDICATEFUNCTION pred_ctime; PREDICATEFUNCTION pred_delete; +PREDICATEFUNCTION pred_cat; PREDICATEFUNCTION pred_empty; PREDICATEFUNCTION pred_exec; PREDICATEFUNCTION pred_execdir; Index: findutils-4.5.2/find/parser.c =================================================================== --- findutils-4.5.2.orig/find/parser.c +++ findutils-4.5.2/find/parser.c @@ -91,6 +91,7 @@ static boolean parse_cnewer PARAM static boolean parse_comma PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_daystart PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_delete PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); +static boolean parse_cat PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_d PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_depth PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_empty PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); @@ -253,6 +254,7 @@ static struct parser_table const parse_t {ARG_TEST, "ctime", parse_time, pred_ctime}, /* POSIX */ PARSE_POSOPT ("daystart", daystart), /* GNU */ PARSE_ACTION ("delete", delete), /* GNU, Mac OS, FreeBSD */ + PARSE_ACTION ("cat", cat), /* GNU */ PARSE_OPTION ("d", d), /* Mac OS X, FreeBSD, NetBSD, OpenBSD, but deprecated in favour of -depth */ PARSE_OPTION ("depth", depth), /* POSIX */ PARSE_TEST ("empty", empty), /* GNU */ @@ -801,6 +803,26 @@ parse_delete (const struct parser_table* }
static boolean +parse_cat (const struct parser_table* entry, char *argv[], int *arg_ptr) +{ + struct predicate *our_pred; + (void) argv; + (void) arg_ptr; + + our_pred = insert_primary (entry); + our_pred->side_effects = our_pred->no_default_print = true; + our_pred->need_stat = our_pred->need_type = false; + our_pred->est_success_rate = 1.0f; + open_stdout(&our_pred->args.printf_vec); + +#ifdef DEBUG + fprintf(stderr, "%s(%s:%d) called.\n", __func__, __FILE__, __LINE__); +#endif + + return true; +} + +static boolean parse_depth (const struct parser_table* entry, char **argv, int *arg_ptr) { (void) entry; Index: findutils-4.5.2/find/pred.c =================================================================== --- findutils-4.5.2.orig/find/pred.c +++ findutils-4.5.2/find/pred.c @@ -445,6 +445,58 @@ pred_delete (const char *pathname, struc }
boolean +pred_cat (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) +{ + FILE * stream = pred_ptr->args.printf_vec.stream; + FILE * input_stream; + char buf[BUFSIZ]; + int fd; + size_t read_len; + + (void) pred_ptr; + (void) stat_buf; + +#ifdef DEBUG + fprintf(stderr, "%s(%s:%d) called.\n", __func__, __FILE__, __LINE__); +#endif + + if ((fd = openat(state.cwd_dir_fd, state.rel_pathname, O_RDONLY +#if defined O_LARGEFILE + |O_LARGEFILE +#endif + )) <> + { + error (0, errno, "%s", safely_quote_err_filename(0, pathname)); + state.exit_status = 1; + return false; + } + + input_stream = fdopen(fd, "r"); + if (input_stream == NULL) + { + error (0, errno, "%s", safely_quote_err_filename(0, pathname)); + state.exit_status = 1; + return false; + } + + while ((read_len = fread(buf, 1, sizeof buf, input_stream)) > 0) + { +#ifdef DEBUG + fprintf(stderr, "%s(%s:%d): read_len = %d, stream = %p\n", + __func__, __FILE__, __LINE__, read_len, stream); +#endif + fwrite(buf, 1, read_len, stream); + + if (read_len <> + break; + } + + fclose(input_stream); + + return true; +} + +boolean pred_empty (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { (void) pathname; Index: findutils-4.5.2/find/tree.c =================================================================== --- findutils-4.5.2.orig/find/tree.c +++ findutils-4.5.2/find/tree.c @@ -906,6 +906,7 @@ static struct pred_cost_lookup costlooku { pred_comma , NeedsNothing, }, { pred_ctime , NeedsStatInfo, }, { pred_delete , NeedsSyncDiskHit }, + { pred_cat , NeedsNothing }, { pred_empty , NeedsStatInfo }, { pred_exec , NeedsEventualExec }, { pred_execdir , NeedsEventualExec },
|
No comments:
Post a Comment