home-etc: src/realpath.c (NEW) - added realpath.c

siefca siefca at pld-linux.org
Wed May 17 18:14:33 CEST 2006


Author: siefca                       Date: Wed May 17 16:14:33 2006 GMT
Module: home-etc                      Tag: HEAD
---- Log message:
- added realpath.c

---- Files affected:
home-etc/src:
   realpath.c (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: home-etc/src/realpath.c
diff -u /dev/null home-etc/src/realpath.c:1.1
--- /dev/null	Wed May 17 18:14:33 2006
+++ home-etc/src/realpath.c	Wed May 17 18:14:28 2006
@@ -0,0 +1,62 @@
+/* realpath: canonize the given pathnames
+ *
+ * Copyright (C) 2006 Pawel Wilk <siefca at gnu.org>,
+ *
+ * This is free software; see the GNU Lesser General Public License version 2
+ * or later for copying conditions.  There is NO warranty.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <home_etc.h>
+
+extern int errno;
+
+int main(int argc, char *argv[])
+{
+  int er = 0;
+  const char *r = NULL;
+  const char **p = NULL;
+  
+  _HE_LIKE_TILDE;
+  
+  if (argc < 2)
+    {
+      fprintf(stderr, "usage: realpath path [...]\n");
+      exit(1);
+    }
+
+  p = argv;
+  p++;
+  while (p && *p)
+    {
+      if (**p == '\0')
+        continue;
+      r = path_canonize(*p, 1);
+      if (r == NULL || *r == '\0')
+        {
+          er = errno;
+          perror("realpath");
+          fprintf(stdout, "-\n"); 
+        }
+      else
+        {
+          fprintf(stdout, "%s\n", r);
+        }
+      p++;
+    }
+
+  if (er)
+    exit(er);
+
+  exit(0);
+}
+
+/*
+  Local Variables:
+  mode: c
+  c-set-style: "gnu"
+  End:
+*/
================================================================


More information about the pld-cvs-commit mailing list