Add memtest support.
[syslinux-debian/hramrach.git] / core / fs / lib / mangle.c
blob8c2077a9e620e811b0776419102051cc6d53ae2f
1 /**
2 * mangle_name:
4 * Mangle a filename pointed to by src into a buffer pointed
5 * to by dst; ends on encountering any whitespace.
6 * dst is preserved.
8 * This verifies that a filename is < FILENAME_MAX characters,
9 * doesn't contain whitespace, zero-pads the output buffer,
10 * and removes redundant slashes.
14 #include <string.h>
15 #include "fs.h"
17 void generic_mangle_name(char *dst, const char *src)
19 char *p = dst;
20 int i = FILENAME_MAX-1;
22 while (not_whitespace(*src)) {
23 if (*src == '/') {
24 if (src[1] == '/') {
25 src++;
26 i--;
27 continue;
30 i--;
31 *dst++ = *src++;
34 while (1) {
35 if (dst == p)
36 break;
37 if (dst[-1] != '/')
38 break;
39 if ((dst[-1] == '/') && ((dst - 1) == p))
40 break;
42 dst--;
43 i++;
46 i++;
47 for (; i > 0; i --)
48 *dst++ = '\0';