FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/fspath.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * FFS pathname manipulation functions | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include "ffs.h" | |
11 #include "limits.h" | |
12 #include "ffslimits.h" | |
13 #include "exitcodes.h" | |
14 | |
15 validate_ffs_pathname(cand) | |
16 char *cand; | |
17 { | |
18 char *cp; | |
19 int depth, c; | |
20 | |
21 cp = cand; | |
22 if (*cp++ != '/') { | |
23 fprintf(stderr, "error: FFS pathnames must be absolute\n"); | |
24 return(-1); | |
25 } | |
26 for (depth = 0; *cp; depth++) { | |
27 if (*cp == '/') { | |
28 fprintf(stderr, | |
29 "error: FFS pathname must not contain duplicate slashes\n"); | |
30 return(-1); | |
31 } | |
32 for (c = 0; *cp && *cp != '/'; cp++) | |
33 c++; | |
34 if (c > MAX_FN_COMPONENT) { | |
35 fprintf(stderr, | |
36 "error: FFS pathname component is too long\n"); | |
37 return(-1); | |
38 } | |
39 if (!*cp) | |
40 continue; | |
41 cp++; | |
42 if (!*cp) { | |
43 fprintf(stderr, | |
44 "error: FFS pathname must not end with a trailing slash\n"); | |
45 return(-1); | |
46 } | |
47 } | |
48 if (depth > MAX_NAME_DEPTH) { | |
49 fprintf(stderr, "error: FFS pathname exceeds depth limit\n"); | |
50 return(-1); | |
51 } | |
52 return(depth); | |
53 } | |
54 | |
55 char * | |
56 pathname_for_ffs_child(parent, childbuf) | |
57 char *parent, *childbuf; | |
58 { | |
59 int depth; | |
60 char *cp; | |
61 | |
62 depth = validate_ffs_pathname(parent); | |
63 if (depth < 0 || depth >= MAX_NAME_DEPTH) | |
64 return(0); | |
65 strcpy(childbuf, parent); | |
66 cp = index(childbuf, '\0'); | |
67 if (depth) | |
68 *cp++ = '/'; | |
69 return(cp); | |
70 } |