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

Function filename_unescape

src/cksum.c:731–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

729 than "n" or another backslash, return NULL. */
730
731static char *
732filename_unescape (char *s, idx_t s_len)
733{
734 char *dst = s;
735
736 for (idx_t i = 0; i < s_len; i++)
737 {
738 switch (s[i])
739 {
740 case '\\':
741 if (i == s_len - 1)
742 {
743 /* File name ends with an unescaped backslash: invalid. */
744 return NULL;
745 }
746 ++i;
747 switch (s[i])
748 {
749 case 'n':
750 *dst++ = '\n';
751 break;
752 case 'r':
753 *dst++ = '\r';
754 break;
755 case '\\':
756 *dst++ = '\\';
757 break;
758 default:
759 /* Only '\', 'n' or 'r' may follow a backslash. */
760 return NULL;
761 }
762 break;
763
764 case '\0':
765 /* The file name may not contain a NUL. */
766 return NULL;
767
768 default:
769 *dst++ = s[i];
770 break;
771 }
772 }
773 if (dst < s + s_len)
774 *dst = '\0';
775
776 return s;
777}
778
779/* Return true if S is a LEN-byte NUL-terminated string of hex or base64
780 digits and has the expected length. Otherwise, return false. */

Callers 2

bsd_split_3Function · 0.85
cksum.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected