| 4449 | Return the number of bytes in *BUF. */ |
| 4450 | |
| 4451 | static size_t |
| 4452 | quote_name_buf (char **inbuf, size_t bufsize, char *name, |
| 4453 | struct quoting_options const *options, |
| 4454 | int needs_general_quoting, size_t *width, bool *pad) |
| 4455 | { |
| 4456 | char *buf = *inbuf; |
| 4457 | size_t displayed_width IF_LINT ( = 0); |
| 4458 | size_t len = 0; |
| 4459 | bool quoted; |
| 4460 | |
| 4461 | enum quoting_style qs = get_quoting_style (options); |
| 4462 | bool needs_further_quoting = qmark_funny_chars |
| 4463 | && (qs == shell_quoting_style |
| 4464 | || qs == shell_always_quoting_style |
| 4465 | || qs == literal_quoting_style); |
| 4466 | |
| 4467 | if (needs_general_quoting != 0) |
| 4468 | { |
| 4469 | len = quotearg_buffer (buf, bufsize, name, -1, options); |
| 4470 | if (bufsize <= len) |
| 4471 | { |
| 4472 | buf = xmalloc (len + 1); |
| 4473 | quotearg_buffer (buf, len + 1, name, -1, options); |
| 4474 | } |
| 4475 | |
| 4476 | quoted = (*name != *buf) || strlen (name) != len; |
| 4477 | } |
| 4478 | else if (needs_further_quoting) |
| 4479 | { |
| 4480 | len = strlen (name); |
| 4481 | if (bufsize <= len) |
| 4482 | buf = xmalloc (len + 1); |
| 4483 | memcpy (buf, name, len + 1); |
| 4484 | |
| 4485 | quoted = false; |
| 4486 | } |
| 4487 | else |
| 4488 | { |
| 4489 | len = strlen (name); |
| 4490 | buf = name; |
| 4491 | quoted = false; |
| 4492 | } |
| 4493 | |
| 4494 | if (needs_further_quoting) |
| 4495 | { |
| 4496 | if (MB_CUR_MAX > 1) |
| 4497 | { |
| 4498 | char const *p = buf; |
| 4499 | char const *plimit = buf + len; |
| 4500 | char *q = buf; |
| 4501 | displayed_width = 0; |
| 4502 | |
| 4503 | while (p < plimit) |
| 4504 | switch (*p) |
| 4505 | { |
| 4506 | case ' ': case '!': case '"': case '#': case '%': |
| 4507 | case '&': case '\'': case '(': case ')': case '*': |
| 4508 | case '+': case ',': case '-': case '.': case '/': |
no test coverage detected