| 187 | } |
| 188 | |
| 189 | int |
| 190 | main (int argc, char **argv) |
| 191 | { |
| 192 | initialize_main (&argc, &argv); |
| 193 | set_program_name (argv[0]); |
| 194 | setlocale (LC_ALL, ""); |
| 195 | bindtextdomain (PACKAGE, LOCALEDIR); |
| 196 | textdomain (PACKAGE); |
| 197 | |
| 198 | atexit (close_stdout); |
| 199 | |
| 200 | parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE_NAME, |
| 201 | Version, true, usage, AUTHORS, |
| 202 | (char const *) NULL); |
| 203 | |
| 204 | char **operands = argv + optind; |
| 205 | char **operand_lim = argv + argc; |
| 206 | if (optind == argc) |
| 207 | *operand_lim++ = bad_cast ("y"); |
| 208 | |
| 209 | /* Buffer data locally once, rather than having the |
| 210 | large overhead of stdio buffering each item. */ |
| 211 | size_t bufalloc = 0; |
| 212 | bool reuse_operand_strings = true; |
| 213 | char **operandp = operands; |
| 214 | do |
| 215 | { |
| 216 | size_t operand_len = strlen (*operandp); |
| 217 | bufalloc += operand_len + 1; |
| 218 | if (operandp + 1 < operand_lim |
| 219 | && *operandp + operand_len + 1 != operandp[1]) |
| 220 | reuse_operand_strings = false; |
| 221 | } |
| 222 | while (++operandp < operand_lim); |
| 223 | |
| 224 | /* Improve performance by using a buffer size greater than BUFSIZ / 2. */ |
| 225 | if (bufalloc <= BUFSIZ / 2) |
| 226 | { |
| 227 | bufalloc = BUFSIZ; |
| 228 | reuse_operand_strings = false; |
| 229 | } |
| 230 | |
| 231 | #if defined __CHERI__ |
| 232 | /* Cheri capability bounds do not allow for this. */ |
| 233 | reuse_operand_strings = false; |
| 234 | #endif |
| 235 | |
| 236 | /* Fill the buffer with one copy of the output. If possible, reuse |
| 237 | the operands strings; this wins when the buffer would be large. */ |
| 238 | char *buf = reuse_operand_strings ? *operands : xmalloc (bufalloc); |
| 239 | size_t bufused = 0; |
| 240 | operandp = operands; |
| 241 | do |
| 242 | { |
| 243 | size_t operand_len = strlen (*operandp); |
| 244 | if (! reuse_operand_strings) |
| 245 | memcpy (buf + bufused, *operandp, operand_len); |
| 246 | bufused += operand_len; |
nothing calls this directly
no test coverage detected