From 71844799b1227c0ae92d48e12d0ba17a193baf6f Mon Sep 17 00:00:00 2001
From: sof <unknown>
Date: Mon, 11 Jan 1999 09:11:52 +0000
Subject: [PATCH] [project @ 1999-01-11 09:11:52 by sof] Added new option -f,
 which forces the creation of 'todir' if it doesn't already exist.

---
 glafp-utils/lndir/lndir.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/glafp-utils/lndir/lndir.c b/glafp-utils/lndir/lndir.c
index 0d77a49ebe66..0c76558615ce 100644
--- a/glafp-utils/lndir/lndir.c
+++ b/glafp-utils/lndir/lndir.c
@@ -305,10 +305,13 @@ char **av;
     char *prog_name = av[0];
     char *fn, *tn;
     struct stat fs, ts;
+    int force=0;
 
     while (++av, --ac) {
 	if (strcmp(*av, "-silent") == 0)
 	    silent = 1;
+	if (strcmp(*av, "-f") == 0)
+	    force = 1;
 	else if (strcmp(*av, "-ignorelinks") == 0)
 	    ignore_links = 1;
 	else if (strcmp(*av, "--") == 0) {
@@ -320,7 +323,7 @@ char **av;
     }
 
     if (ac < 1 || ac > 2)
-	quit (1, "usage: %s [-silent] [-ignorelinks] fromdir [todir]",
+	quit (1, "usage: %s [-f] [-silent] [-ignorelinks] fromdir [todir]",
 	      prog_name);
 
     fn = av[0];
@@ -330,14 +333,20 @@ char **av;
 	tn = ".";
 
     /* to directory */
-    if (stat (tn, &ts) < 0)
+    if (stat (tn, &ts) < 0) {
+      if (force && (tn[0] != '.' || tn[1] != '\0') ) {
+         mkdir(tn, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
+      } 
+      else {
 	quiterr (1, tn);
 #ifdef S_ISDIR
-    if (!(S_ISDIR(ts.st_mode)))
+        if (!(S_ISDIR(ts.st_mode)))
 #else
-    if (!(ts.st_mode & S_IFDIR))
+        if (!(ts.st_mode & S_IFDIR))
 #endif
-	quit (2, "%s: Not a directory", tn);
+	   quit (2, "%s: Not a directory", tn);
+      }
+    }
     if (chdir (tn) < 0)
 	quiterr (1, tn);
 
-- 
GitLab