1 /** 2 * mangle_name: 3 * 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. 7 * 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. 11 * 12 */ 13 14 #include <string.h> 15 #include "fs.h" 16 generic_mangle_name(char * dst,const char * src)17void generic_mangle_name(char *dst, const char *src) 18 { 19 char *p = dst; 20 int i = FILENAME_MAX-1; 21 22 while (not_whitespace(*src)) { 23 if (*src == '/') { 24 if (src[1] == '/') { 25 src++; 26 i--; 27 continue; 28 } 29 } 30 i--; 31 *dst++ = *src++; 32 } 33 34 while (1) { 35 if (dst == p) 36 break; 37 if (dst[-1] != '/') 38 break; 39 if ((dst[-1] == '/') && ((dst - 1) == p)) 40 break; 41 42 dst--; 43 i++; 44 } 45 46 i++; 47 for (; i > 0; i --) 48 *dst++ = '\0'; 49 } 50