| @@ -16,6 +16,8 @@ |
| 16 | 16 | | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | 17 | | */ |
| 18 | 18 | | |
| 19 | + | #define _XOPEN_SOURCE 700 |
| 20 | + | |
| 19 | 21 | | #include <stdlib.h> |
| 20 | 22 | | #include <stdio.h> |
| 21 | 23 | | #include <string.h> |
| @@ -59,7 +61,7 @@ img_t img; |
| 59 | 61 | | tns_t tns; |
| 60 | 62 | | win_t win; |
| 61 | 63 | | |
| 62 | | − | const char **filenames; |
| 64 | + | char **filenames; |
| 63 | 65 | | int filecnt, fileidx; |
| 64 | 66 | | size_t filesize; |
| 65 | 67 | | |
| @@ -88,7 +90,7 @@ void remove_file(int n, unsigned char silent) { |
| 88 | 90 | | |
| 89 | 91 | | if (n + 1 < filecnt) |
| 90 | 92 | | memmove(filenames + n, filenames + n + 1, (filecnt - n - 1) * |
| 91 | | − | sizeof(const char*)); |
| 93 | + | sizeof(char*)); |
| 92 | 94 | | if (n + 1 < tns.cnt) { |
| 93 | 95 | | memmove(tns.thumbs + n, tns.thumbs + n + 1, (tns.cnt - n - 1) * |
| 94 | 96 | | sizeof(thumb_t)); |
| @@ -150,7 +152,7 @@ void update_title() { |
| 150 | 152 | | win_set_title(&win, win_title); |
| 151 | 153 | | } |
| 152 | 154 | | |
| 153 | | − | int check_append(const char *filename) { |
| 155 | + | int check_append(char *filename) { |
| 154 | 156 | | if (!filename) |
| 155 | 157 | | return 0; |
| 156 | 158 | | |
| @@ -160,8 +162,7 @@ int check_append(const char *filename) { |
| 160 | 162 | | } else { |
| 161 | 163 | | if (fileidx == filecnt) { |
| 162 | 164 | | filecnt *= 2; |
| 163 | | − | filenames = (const char**) s_realloc(filenames, |
| 164 | | − | filecnt * sizeof(const char*)); |
| 165 | + | filenames = (char**) s_realloc(filenames, filecnt * sizeof(char*)); |
| 165 | 166 | | } |
| 166 | 167 | | filenames[fileidx++] = filename; |
| 167 | 168 | | return 1; |
| @@ -173,8 +174,9 @@ int fncmp(const void *a, const void *b) { |
| 173 | 174 | | } |
| 174 | 175 | | |
| 175 | 176 | | int main(int argc, char **argv) { |
| 176 | | − | int i, start; |
| 177 | | − | const char *filename; |
| 177 | + | int i, len, start; |
| 178 | + | size_t n; |
| 179 | + | char *filename = NULL; |
| 178 | 180 | | struct stat fstats; |
| 179 | 181 | | r_dir_t dir; |
| 180 | 182 | | |
| @@ -196,13 +198,16 @@ int main(int argc, char **argv) { |
| 196 | 198 | | else |
| 197 | 199 | | filecnt = options->filecnt; |
| 198 | 200 | | |
| 199 | | − | filenames = (const char**) s_malloc(filecnt * sizeof(const char*)); |
| 201 | + | filenames = (char**) s_malloc(filecnt * sizeof(char*)); |
| 200 | 202 | | fileidx = 0; |
| 201 | 203 | | |
| 202 | 204 | | if (options->from_stdin) { |
| 203 | | − | while ((filename = readline(stdin))) { |
| 205 | + | while ((len = getline(&filename, &n, stdin)) > 0) { |
| 206 | + | if (filename[len-1] == '\n') |
| 207 | + | filename[len-1] = '\0'; |
| 204 | 208 | | if (!*filename || !check_append(filename)) |
| 205 | | − | free((void*) filename); |
| 209 | + | free(filename); |
| 210 | + | filename = NULL; |
| 206 | 211 | | } |
| 207 | 212 | | } else { |
| 208 | 213 | | for (i = 0; i < options->filecnt; ++i) { |