diff options
author | Bert <ber.t@gmx.com> | 2011-05-29 11:45:58 +0200 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-05-29 11:45:58 +0200 |
commit | ea23115af449e086ba05c9757ad22108944f6ec2 (patch) | |
tree | c52e943902632792f24f17c9681cacd2b6a04f01 /main.c | |
parent | 2252a0148d11fc988131eb0bf6397453427d67e8 (diff) | |
download | nsxiv-ea23115af449e086ba05c9757ad22108944f6ec2.tar.zst |
Use getline instead of readline
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 25 |
1 files changed, 15 insertions, 10 deletions
@@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define _XOPEN_SOURCE 700 + #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -59,7 +61,7 @@ img_t img; tns_t tns; win_t win; -const char **filenames; +char **filenames; int filecnt, fileidx; size_t filesize; @@ -88,7 +90,7 @@ void remove_file(int n, unsigned char silent) { if (n + 1 < filecnt) memmove(filenames + n, filenames + n + 1, (filecnt - n - 1) * - sizeof(const char*)); + sizeof(char*)); if (n + 1 < tns.cnt) { memmove(tns.thumbs + n, tns.thumbs + n + 1, (tns.cnt - n - 1) * sizeof(thumb_t)); @@ -150,7 +152,7 @@ void update_title() { win_set_title(&win, win_title); } -int check_append(const char *filename) { +int check_append(char *filename) { if (!filename) return 0; @@ -160,8 +162,7 @@ int check_append(const char *filename) { } else { if (fileidx == filecnt) { filecnt *= 2; - filenames = (const char**) s_realloc(filenames, - filecnt * sizeof(const char*)); + filenames = (char**) s_realloc(filenames, filecnt * sizeof(char*)); } filenames[fileidx++] = filename; return 1; @@ -173,8 +174,9 @@ int fncmp(const void *a, const void *b) { } int main(int argc, char **argv) { - int i, start; - const char *filename; + int i, len, start; + size_t n; + char *filename = NULL; struct stat fstats; r_dir_t dir; @@ -196,13 +198,16 @@ int main(int argc, char **argv) { else filecnt = options->filecnt; - filenames = (const char**) s_malloc(filecnt * sizeof(const char*)); + filenames = (char**) s_malloc(filecnt * sizeof(char*)); fileidx = 0; if (options->from_stdin) { - while ((filename = readline(stdin))) { + while ((len = getline(&filename, &n, stdin)) > 0) { + if (filename[len-1] == '\n') + filename[len-1] = '\0'; if (!*filename || !check_append(filename)) - free((void*) filename); + free(filename); + filename = NULL; } } else { for (i = 0; i < options->filecnt; ++i) { |