]> Sergey Matveev's repositories - nnn.git/commitdiff
Default to cwd if not argument is provided
authorsin <sin@2f30.org>
Tue, 21 Oct 2014 10:29:41 +0000 (11:29 +0100)
committersin <sin@2f30.org>
Tue, 21 Oct 2014 10:29:41 +0000 (11:29 +0100)
noice.c

diff --git a/noice.c b/noice.c
index d78cf5e951858368852c305d38a6c7be994bb718..384598096c45c24f2aa7308a641dcb4dd9b9d11f 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -6,6 +6,7 @@
 #include <dirent.h>
 #include <curses.h>
 #include <libgen.h>
+#include <limits.h>
 #include <locale.h>
 #include <regex.h>
 #include <stdlib.h>
@@ -613,9 +614,17 @@ out:
 int
 main(int argc, char *argv[])
 {
-       char *ipath = argv[1] != NULL ? argv[1] : "/";
+       char cwd[PATH_MAX], *ipath;
        char *ifilter = "^[^.].*"; /* Hide dotfiles */
 
+       if (argv[1] != NULL) {
+               ipath = argv[1];
+       } else {
+               ipath = getcwd(cwd, sizeof(cwd));
+               if (ipath == NULL)
+                       ipath = "/";
+       }
+
        /* Test initial path */
        if (!testopendir(ipath))
                printerr(1, ipath);