diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fspath.c	Sat Jun 11 00:13:35 2016 +0000
@@ -0,0 +1,70 @@
+/*
+ * FFS pathname manipulation functions
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "ffs.h"
+#include "limits.h"
+#include "ffslimits.h"
+#include "exitcodes.h"
+
+validate_ffs_pathname(cand)
+	char *cand;
+{
+	char *cp;
+	int depth, c;
+
+	cp = cand;
+	if (*cp++ != '/') {
+		fprintf(stderr, "error: FFS pathnames must be absolute\n");
+		return(-1);
+	}
+	for (depth = 0; *cp; depth++) {
+		if (*cp == '/') {
+			fprintf(stderr,
+		"error: FFS pathname must not contain duplicate slashes\n");
+			return(-1);
+		}
+		for (c = 0; *cp && *cp != '/'; cp++)
+			c++;
+		if (c > MAX_FN_COMPONENT) {
+			fprintf(stderr,
+				"error: FFS pathname component is too long\n");
+			return(-1);
+		}
+		if (!*cp)
+			continue;
+		cp++;
+		if (!*cp) {
+			fprintf(stderr,
+		"error: FFS pathname must not end with a trailing slash\n");
+			return(-1);
+		}
+	}
+	if (depth > MAX_NAME_DEPTH) {
+		fprintf(stderr, "error: FFS pathname exceeds depth limit\n");
+		return(-1);
+	}
+	return(depth);
+}
+
+char *
+pathname_for_ffs_child(parent, childbuf)
+	char *parent, *childbuf;
+{
+	int depth;
+	char *cp;
+
+	depth = validate_ffs_pathname(parent);
+	if (depth < 0 || depth >= MAX_NAME_DEPTH)
+		return(0);
+	strcpy(childbuf, parent);
+	cp = index(childbuf, '\0');
+	if (depth)
+		*cp++ = '/';
+	return(cp);
+}