Krolyxon
Commit 2df3320

Branches

Refs →

nsxiv2df3320

apply -0 to stdin/-i as well

while i was initially against this since it can be done via `xargs -0`.
the problem with this approach is that there's a limit to how many args
a command can recieve, leading to problem like this [0] when opening
large (1k~) amount of images.

there's no limit on how big stdin can be, so being able to read a
null-separated list from stdin doesn't have this problem.

[0]: https://github.com/ranger/ranger/pull/2307#issuecomment-818683515
Author
NRK
Date
2021-11-19 16:08 +0600
Committer
N-R-K · 2021-11-19 17:02 +0600
Parent
4a282da
Commit
2df33208d76159ffacffce3c8a8edc3a5ad7ea7b

+10 −6

2 files changed

  1. M main.c +9 −5
  2. M nsxiv.1 +1 −1
M main.c View
@@ -105,6 +105,14 @@ void cleanup(void)
105105 win_close(&win);
106106 }
107107
108+static bool xgetline(char **lineptr, size_t *n)
109+{
110+ ssize_t len = getdelim(lineptr, n, options->using_null ? '\0' : '\n', stdin);
111+ if (!options->using_null && len > 0 && (*lineptr)[len-1] == '\n')
112+ (*lineptr)[len-1] = '\0';
113+ return len > 0;
114+}
115+
108116 void check_add_file(char *filename, bool given)
109117 {
110118 char *path;
@@ -853,7 +861,6 @@ int main(int argc, char *argv[])
853861 {
854862 int i, start;
855863 size_t n;
856− ssize_t len;
857864 char *filename;
858865 const char *homedir, *dsuffix = "";
859866 struct stat fstats;
@@ -889,11 +896,8 @@ int main(int argc, char *argv[])
889896 if (options->from_stdin) {
890897 n = 0;
891898 filename = NULL;
892− while ((len = getline(&filename, &n, stdin)) > 0) {
893− if (filename[len-1] == '\n')
894− filename[len-1] = '\0';
899+ while (xgetline(&filename, &n))
895900 check_add_file(filename, true);
896− }
897901 free(filename);
898902 }
899903
M nsxiv.1 View
@@ -128,7 +128,7 @@ Set zoom level to ZOOM percent.
128128 .TP
129129 .B \-0
130130 Use NULL-separator. With this option output of \-o and file-list sent to the
131−key-handler will be seperated by a NULL character.
131+key-handler and the input of \-i will be seperated by a NULL character.
132132 .SH KEYBOARD COMMANDS
133133 .SS General
134134 The following keyboard commands are available in both image and thumbnail mode: