FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fspath.c @ 701:615fb8847d3f
top level README: typo fix
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 02 Oct 2014 18:48:12 +0000 |
parents | 3dd74b16df82 |
children |
rev | line source |
---|---|
295
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * FFS pathname manipulation functions |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include "ffs.h" |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "limits.h" |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "ffslimits.h" |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "exitcodes.h" |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 validate_ffs_pathname(cand) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 char *cand; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 char *cp; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 int depth, c; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 cp = cand; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 if (*cp++ != '/') { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 fprintf(stderr, "error: FFS pathnames must be absolute\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 return(-1); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 for (depth = 0; *cp; depth++) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 if (*cp == '/') { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 fprintf(stderr, |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 "error: FFS pathname must not contain duplicate slashes\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 return(-1); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 for (c = 0; *cp && *cp != '/'; cp++) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 c++; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (c > MAX_FN_COMPONENT) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 fprintf(stderr, |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 "error: FFS pathname component is too long\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 return(-1); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (!*cp) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 continue; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 cp++; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 if (!*cp) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 fprintf(stderr, |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 "error: FFS pathname must not end with a trailing slash\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 return(-1); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (depth > MAX_NAME_DEPTH) { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 fprintf(stderr, "error: FFS pathname exceeds depth limit\n"); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 return(-1); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 return(depth); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 char * |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 pathname_for_ffs_child(parent, childbuf) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 char *parent, *childbuf; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 { |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 int depth; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 char *cp; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 depth = validate_ffs_pathname(parent); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 if (depth < 0 || depth >= MAX_NAME_DEPTH) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 return(0); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 strcpy(childbuf, parent); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 cp = index(childbuf, '\0'); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (depth) |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 *cp++ = '/'; |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 return(cp); |
3dd74b16df82
fc-fsio: pathname recursion handling revamped
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 } |