summaryrefslogtreecommitdiffstats
path: root/lib/librpc/demo/dir/dir_proc.c
diff options
context:
space:
mode:
authorrgrimes <rgrimes@FreeBSD.org>1994-05-27 05:00:24 +0000
committerrgrimes <rgrimes@FreeBSD.org>1994-05-27 05:00:24 +0000
commitbe22b15ae2ff8d7fe06b6e14fddf0c5b444a95da (patch)
treea18a706dffa5baf86a3b12bbfb4f81caa097f349 /lib/librpc/demo/dir/dir_proc.c
parent2a27bd86e6002c871e3b5561a5334653bb222a77 (diff)
downloadFreeBSD-src-be22b15ae2ff8d7fe06b6e14fddf0c5b444a95da.zip
FreeBSD-src-be22b15ae2ff8d7fe06b6e14fddf0c5b444a95da.tar.gz
BSD 4.4 Lite Lib Sources
Diffstat (limited to 'lib/librpc/demo/dir/dir_proc.c')
-rw-r--r--lib/librpc/demo/dir/dir_proc.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/librpc/demo/dir/dir_proc.c b/lib/librpc/demo/dir/dir_proc.c
new file mode 100644
index 0000000..9f7522a
--- /dev/null
+++ b/lib/librpc/demo/dir/dir_proc.c
@@ -0,0 +1,55 @@
+/* @(#)dir_proc.c 2.1 88/08/02 4.0 RPCSRC */
+/*
+ * dir_proc.c: remote readdir implementation
+ */
+#include <rpc/rpc.h>
+#include <sys/dir.h>
+#include "dir.h"
+
+extern int errno;
+extern char *malloc();
+extern char *strcpy();
+
+readdir_res *
+readdir_1(dirname)
+ nametype *dirname;
+{
+ DIR *dirp;
+ struct direct *d;
+ namelist nl;
+ namelist *nlp;
+ static readdir_res res; /* must be static! */
+
+ /*
+ * Open directory
+ */
+ dirp = opendir(*dirname);
+ if (dirp == NULL) {
+ res.errno = errno;
+ return (&res);
+ }
+
+ /*
+ * Free previous result
+ */
+ xdr_free(xdr_readdir_res, &res);
+
+ /*
+ * Collect directory entries
+ */
+ nlp = &res.readdir_res_u.list;
+ while (d = readdir(dirp)) {
+ nl = *nlp = (namenode *) malloc(sizeof(namenode));
+ nl->name = malloc(strlen(d->d_name)+1);
+ strcpy(nl->name, d->d_name);
+ nlp = &nl->next;
+ }
+ *nlp = NULL;
+
+ /*
+ * Return the result
+ */
+ res.errno = 0;
+ closedir(dirp);
+ return (&res);
+}
OpenPOWER on IntegriCloud