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
+10 −6
2 files changed
| @@ -105,6 +105,14 @@ void cleanup(void) | |||
| 105 | 105 | win_close(&win); | |
| 106 | 106 | } | |
| 107 | 107 | ||
| 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 | + | ||
| 108 | 116 | void check_add_file(char *filename, bool given) | |
| 109 | 117 | { | |
| 110 | 118 | char *path; | |
| @@ -853,7 +861,6 @@ int main(int argc, char *argv[]) | |||
| 853 | 861 | { | |
| 854 | 862 | int i, start; | |
| 855 | 863 | size_t n; | |
| 856 | − | ssize_t len; | |
| 857 | 864 | char *filename; | |
| 858 | 865 | const char *homedir, *dsuffix = ""; | |
| 859 | 866 | struct stat fstats; | |
| @@ -889,11 +896,8 @@ int main(int argc, char *argv[]) | |||
| 889 | 896 | if (options->from_stdin) { | |
| 890 | 897 | n = 0; | |
| 891 | 898 | 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)) | |
| 895 | 900 | check_add_file(filename, true); | |
| 896 | − | } | |
| 897 | 901 | free(filename); | |
| 898 | 902 | } | |
| 899 | 903 | ||
| @@ -128,7 +128,7 @@ Set zoom level to ZOOM percent. | |||
| 128 | 128 | .TP | |
| 129 | 129 | .B \-0 | |
| 130 | 130 | 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. | |
| 132 | 132 | .SH KEYBOARD COMMANDS | |
| 133 | 133 | .SS General | |
| 134 | 134 | The following keyboard commands are available in both image and thumbnail mode: | |