MCPcopy Create free account
hub / github.com/coreutils/coreutils / file_escape

Function file_escape

src/ls.c:4668–4687  ·  view source on GitHub ↗

%XX escape any input out of range as defined in RFC3986, and also if PATH, convert all path separators to '/'. */

Source from the content-addressed store, hash-verified

4666/* %XX escape any input out of range as defined in RFC3986,
4667 and also if PATH, convert all path separators to '/'. */
4668static char *
4669file_escape (char const *str, bool path)
4670{
4671 char *esc = xnmalloc (3, strlen (str) + 1);
4672 char *p = esc;
4673 while (*str)
4674 {
4675 if (path && ISSLASH (*str))
4676 {
4677 *p++ = '/';
4678 str++;
4679 }
4680 else if (RFC3986[to_uchar (*str)])
4681 *p++ = *str++;
4682 else
4683 p += sprintf (p, "%%%02x", to_uchar (*str++));
4684 }
4685 *p = '\0';
4686 return esc;
4687}
4688
4689static size_t
4690quote_name (char const *name, struct quoting_options const *options,

Callers 1

quote_nameFunction · 0.85

Calls 1

to_ucharFunction · 0.85

Tested by

no test coverage detected