nsxiv6e575b0
Strict conformance to IEEE Std 1003.1-2001
+64 −38
8 files changed
- M commands.c +2 −2
- M image.c +2 −0
- M main.c +7 −2
- M options.c +2 −2
- M thumbs.c +9 −19
- M util.c +38 −6
- M util.h +2 −7
- M window.c +2 −0
| @@ -16,9 +16,9 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | − | #define _POSIX_C_SOURCE 200112L /* for setenv(3) */ | |
| 20 | − | #include <stdlib.h> | |
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 21 | 20 | ||
| 21 | + | #include <stdlib.h> | |
| 22 | 22 | #include <string.h> | |
| 23 | 23 | #include <unistd.h> | |
| 24 | 24 | #include <sys/wait.h> | |
| @@ -16,6 +16,8 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | ||
| 19 | 21 | #include <string.h> | |
| 20 | 22 | #include <unistd.h> | |
| 21 | 23 | ||
| @@ -16,6 +16,8 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | ||
| 19 | 21 | #include <stdlib.h> | |
| 20 | 22 | #include <stdio.h> | |
| 21 | 23 | #include <string.h> | |
| @@ -430,8 +432,9 @@ int fncmp(const void *a, const void *b) { | |||
| 430 | 432 | } | |
| 431 | 433 | ||
| 432 | 434 | int main(int argc, char **argv) { | |
| 433 | − | int i, len, start; | |
| 435 | + | int i, start; | |
| 434 | 436 | size_t n; | |
| 437 | + | ssize_t len; | |
| 435 | 438 | char *filename; | |
| 436 | 439 | struct stat fstats; | |
| 437 | 440 | r_dir_t dir; | |
| @@ -460,11 +463,13 @@ int main(int argc, char **argv) { | |||
| 460 | 463 | /* build file list: */ | |
| 461 | 464 | if (options->from_stdin) { | |
| 462 | 465 | filename = NULL; | |
| 463 | − | while ((len = getline(&filename, &n, stdin)) > 0) { | |
| 466 | + | while ((len = get_line(&filename, &n, stdin)) > 0) { | |
| 464 | 467 | if (filename[len-1] == '\n') | |
| 465 | 468 | filename[len-1] = '\0'; | |
| 466 | 469 | check_add_file(filename); | |
| 467 | 470 | } | |
| 471 | + | if (filename) | |
| 472 | + | free(filename); | |
| 468 | 473 | } else { | |
| 469 | 474 | for (i = 0; i < options->filecnt; i++) { | |
| 470 | 475 | filename = options->filenames[i]; | |
| @@ -16,12 +16,12 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | − | #define _POSIX_C_SOURCE 2 /* for getopt(3) */ | |
| 20 | − | #include <unistd.h> | |
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 21 | 20 | ||
| 22 | 21 | #include <stdlib.h> | |
| 23 | 22 | #include <string.h> | |
| 24 | 23 | #include <stdio.h> | |
| 24 | + | #include <unistd.h> | |
| 25 | 25 | ||
| 26 | 26 | #include "options.h" | |
| 27 | 27 | #include "util.h" | |
| @@ -16,12 +16,14 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | ||
| 19 | 21 | #include <stdlib.h> | |
| 20 | 22 | #include <string.h> | |
| 21 | − | #include <sys/time.h> | |
| 22 | 23 | #include <sys/types.h> | |
| 23 | 24 | #include <sys/stat.h> | |
| 24 | 25 | #include <unistd.h> | |
| 26 | + | #include <utime.h> | |
| 25 | 27 | ||
| 26 | 28 | #include "thumbs.h" | |
| 27 | 29 | #include "util.h" | |
| @@ -29,11 +31,6 @@ | |||
| 29 | 31 | #define _THUMBS_CONFIG | |
| 30 | 32 | #include "config.h" | |
| 31 | 33 | ||
| 32 | − | #ifdef __NetBSD__ | |
| 33 | − | #define st_mtim st_mtimespec | |
| 34 | − | #define st_atim st_atimespec | |
| 35 | − | #endif | |
| 36 | − | ||
| 37 | 34 | #ifdef EXIF_SUPPORT | |
| 38 | 35 | void exif_auto_orientate(const fileinfo_t*); | |
| 39 | 36 | #endif | |
| @@ -76,12 +73,8 @@ Imlib_Image* tns_cache_load(const char *filepath) { | |||
| 76 | 73 | return NULL; | |
| 77 | 74 | ||
| 78 | 75 | if ((cfile = tns_cache_filepath(filepath))) { | |
| 79 | − | if (!stat(cfile, &cstats) && | |
| 80 | − | cstats.st_mtim.tv_sec == fstats.st_mtim.tv_sec && | |
| 81 | − | cstats.st_mtim.tv_nsec / 1000 == fstats.st_mtim.tv_nsec / 1000) | |
| 82 | − | { | |
| 76 | + | if (!stat(cfile, &cstats) && cstats.st_mtime == fstats.st_mtime) | |
| 83 | 77 | im = imlib_load_image(cfile); | |
| 84 | − | } | |
| 85 | 78 | free(cfile); | |
| 86 | 79 | } | |
| 87 | 80 | ||
| @@ -91,7 +84,7 @@ Imlib_Image* tns_cache_load(const char *filepath) { | |||
| 91 | 84 | void tns_cache_write(thumb_t *t, Bool force) { | |
| 92 | 85 | char *cfile, *dirend; | |
| 93 | 86 | struct stat cstats, fstats; | |
| 94 | − | struct timeval times[2]; | |
| 87 | + | struct utimbuf times; | |
| 95 | 88 | Imlib_Load_Error err = 0; | |
| 96 | 89 | ||
| 97 | 90 | if (!t || !t->im || !t->file || !t->file->name || !t->file->path) | |
| @@ -101,10 +94,7 @@ void tns_cache_write(thumb_t *t, Bool force) { | |||
| 101 | 94 | return; | |
| 102 | 95 | ||
| 103 | 96 | if ((cfile = tns_cache_filepath(t->file->path))) { | |
| 104 | − | if (force || stat(cfile, &cstats) || | |
| 105 | − | cstats.st_mtim.tv_sec != fstats.st_mtim.tv_sec || | |
| 106 | − | cstats.st_mtim.tv_nsec / 1000 != fstats.st_mtim.tv_nsec / 1000) | |
| 107 | − | { | |
| 97 | + | if (force || stat(cfile, &cstats) || cstats.st_mtime != fstats.st_mtime) { | |
| 108 | 98 | if ((dirend = strrchr(cfile, '/'))) { | |
| 109 | 99 | *dirend = '\0'; | |
| 110 | 100 | err = r_mkdir(cfile); | |
| @@ -120,9 +110,9 @@ void tns_cache_write(thumb_t *t, Bool force) { | |||
| 120 | 110 | if (err) { | |
| 121 | 111 | warn("could not cache thumbnail: %s", t->file->name); | |
| 122 | 112 | } else { | |
| 123 | − | TIMESPEC_TO_TIMEVAL(×[0], &fstats.st_atim); | |
| 124 | − | TIMESPEC_TO_TIMEVAL(×[1], &fstats.st_mtim); | |
| 125 | − | utimes(cfile, times); | |
| 113 | + | times.actime = fstats.st_atime; | |
| 114 | + | times.modtime = fstats.st_mtime; | |
| 115 | + | utime(cfile, ×); | |
| 126 | 116 | } | |
| 127 | 117 | } | |
| 128 | 118 | free(cfile); | |
| @@ -16,6 +16,8 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | ||
| 19 | 21 | #include <stdlib.h> | |
| 20 | 22 | #include <string.h> | |
| 21 | 23 | #include <sys/types.h> | |
| @@ -27,6 +29,7 @@ | |||
| 27 | 29 | #include "util.h" | |
| 28 | 30 | ||
| 29 | 31 | enum { | |
| 32 | + | BUF_SIZE = 1024, | |
| 30 | 33 | DNAME_CNT = 512, | |
| 31 | 34 | FNAME_LEN = 1024 | |
| 32 | 35 | }; | |
| @@ -87,6 +90,39 @@ void die(const char* fmt, ...) { | |||
| 87 | 90 | exit(1); | |
| 88 | 91 | } | |
| 89 | 92 | ||
| 93 | + | ssize_t get_line(char **buf, size_t *n, FILE *stream) { | |
| 94 | + | size_t len; | |
| 95 | + | char *s; | |
| 96 | + | ||
| 97 | + | if (!stream || feof(stream) || ferror(stream)) | |
| 98 | + | return -1; | |
| 99 | + | ||
| 100 | + | if (!*buf || !*n) { | |
| 101 | + | *n = BUF_SIZE; | |
| 102 | + | *buf = (char*) s_malloc(*n); | |
| 103 | + | } | |
| 104 | + | s = *buf; | |
| 105 | + | ||
| 106 | + | while (1) { | |
| 107 | + | if (!fgets(s, *n - (s - *buf), stream)) | |
| 108 | + | return -1; | |
| 109 | + | len = strlen(s); | |
| 110 | + | if (feof(stream)) | |
| 111 | + | break; | |
| 112 | + | if (len > 0 && s[len-1] == '\n') | |
| 113 | + | break; | |
| 114 | + | if (len + 1 == *n - (s - *buf)) { | |
| 115 | + | *buf = (char*) s_realloc(*buf, 2 * *n); | |
| 116 | + | s = *buf + *n - 1; | |
| 117 | + | *n *= 2; | |
| 118 | + | } else { | |
| 119 | + | s += len; | |
| 120 | + | } | |
| 121 | + | } | |
| 122 | + | ||
| 123 | + | return s - *buf + len; | |
| 124 | + | } | |
| 125 | + | ||
| 90 | 126 | void size_readable(float *size, const char **unit) { | |
| 91 | 127 | const char *units[] = { "", "K", "M", "G" }; | |
| 92 | 128 | int i; | |
| @@ -98,13 +134,9 @@ void size_readable(float *size, const char **unit) { | |||
| 98 | 134 | ||
| 99 | 135 | char* absolute_path(const char *filename) { | |
| 100 | 136 | size_t len; | |
| 101 | − | char *path = NULL; | |
| 102 | 137 | const char *basename; | |
| 103 | − | char *dirname = NULL; | |
| 104 | − | char *cwd = NULL; | |
| 105 | − | char *twd = NULL; | |
| 106 | − | char *dir; | |
| 107 | − | char *s; | |
| 138 | + | char *dir, *dirname = NULL, *path = NULL, *s; | |
| 139 | + | char *cwd = NULL, *twd = NULL; | |
| 108 | 140 | ||
| 109 | 141 | if (!filename || *filename == '\0' || *filename == '/') | |
| 110 | 142 | return NULL; | |
| @@ -45,13 +45,6 @@ | |||
| 45 | 45 | (tv)->tv_usec += (t) % 1000 * 1000; \ | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | − | #ifndef TIMESPEC_TO_TIMEVAL | |
| 49 | − | #define TIMESPEC_TO_TIMEVAL(tv,ts) { \ | |
| 50 | − | (tv)->tv_sec = (ts)->tv_sec; \ | |
| 51 | − | (tv)->tv_usec = (ts)->tv_nsec / 1000; \ | |
| 52 | − | } | |
| 53 | − | #endif | |
| 54 | − | ||
| 55 | 48 | typedef struct { | |
| 56 | 49 | DIR *dir; | |
| 57 | 50 | char *name; | |
| @@ -69,6 +62,8 @@ char* s_strdup(char*); | |||
| 69 | 62 | void warn(const char*, ...); | |
| 70 | 63 | void die(const char*, ...); | |
| 71 | 64 | ||
| 65 | + | ssize_t get_line(char**, size_t*, FILE*); | |
| 66 | + | ||
| 72 | 67 | void size_readable(float*, const char**); | |
| 73 | 68 | ||
| 74 | 69 | char* absolute_path(const char*); | |
| @@ -16,6 +16,8 @@ | |||
| 16 | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | + | #define _POSIX_C_SOURCE 200112L | |
| 20 | + | ||
| 19 | 21 | #include <string.h> | |
| 20 | 22 | #include <X11/Xutil.h> | |
| 21 | 23 | #include <X11/cursorfont.h> | |