Copyright clean-up (part 1):
[AROS.git] / arch / all-hosted / filesys / emul_handler / filenames.c
blob492836d8a8f2e7aa51710b31c8265b5320c9d177
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <dos/dos.h>
9 #include <string.h>
11 /*********************************************************************************************/
14 * Create a plain path out of the supplied filename.
15 * Eg 'path1/path2//path3/' becomes 'path1/path3'.
17 BOOL shrink(char *filename)
19 char *s, *s1, *s2;
20 unsigned long len;
22 /* We skip the first slash because it separates volume root prefix and the actual pathname */
23 s = filename;
24 if (*s == '/')
25 s++;
27 for(;;)
29 /* leading slashes? --> return FALSE. */
30 if (*s == '/')
31 return FALSE;
33 /* remove superflous paths (ie paths that are followed by '//') */
34 s1 = strstr(s, "//");
35 if (s1 == NULL)
36 break;
37 s2 = s1;
38 while (s2 > filename)
40 if (s2[-1] == '/')
41 break;
42 s2--;
45 memmove(s2, s1+2, strlen(s1+1));
48 /* strip trailing slash */
49 len=strlen(filename);
50 if (len && filename[len-1]=='/')
51 filename[len-1]=0;
53 return TRUE;
56 /* Validate file name */
57 ULONG validate(char *filename)
59 char *s = filename;
61 while (*s)
63 if (*s == '.') {
64 do {
65 s++;
66 } while (*s == '.');
67 if ((*s == '/') || (!*s)) {
68 D(bug("[emul] Bad file name, contains dots-only component\n"));
69 return ERROR_INVALID_COMPONENT_NAME;
72 do {
73 s++;
74 } while ((*s != '/') && *s);
75 while (*s == '/')
76 s++;
79 return 0;
82 /* Append file name to an existing path */
83 char *append(char *c, char *filename)
85 char *s;
87 *c++ = '/';
88 for (s = filename; *s; s++)
89 *c++ = *s;
90 return c;
93 /* Find start position of the file name in path string */
94 long startpos(char *name, long i)
96 /* look for the first '/' in the filename starting at the end */
97 while (i != 0 && name[i] != '/')
98 i--;
100 return i;
103 /* Copy file name with possible conversion */
104 void copyname(char *result, char *name, long i)
106 strncpy(result, name, i);
109 /* Go to next part in path string */
110 char *nextpart(char *sp)
112 char *sp_end;
114 for(sp_end = sp + 1; sp_end[0] != '\0' && sp_end[0] != '/'; sp_end++);
116 return sp_end;