Krolyxon
Commit 6e575b0

Branches

Refs →

nsxiv6e575b0

Strict conformance to IEEE Std 1003.1-2001

Author
Bert
Date
2011-09-08 20:54 +0200
Parent
3a4f386
Commit
6e575b0f721e1743fab098004d7dc26de5c7db49

+64 −38

8 files changed

  1. M commands.c +2 −2
  2. M image.c +2 −0
  3. M main.c +7 −2
  4. M options.c +2 −2
  5. M thumbs.c +9 −19
  6. M util.c +38 −6
  7. M util.h +2 −7
  8. M window.c +2 −0
M commands.c View
@@ -16,9 +16,9 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19−#define _POSIX_C_SOURCE 200112L /* for setenv(3) */
20−#include <stdlib.h>
19+#define _POSIX_C_SOURCE 200112L
2120
21+#include <stdlib.h>
2222 #include <string.h>
2323 #include <unistd.h>
2424 #include <sys/wait.h>
M image.c View
@@ -16,6 +16,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#define _POSIX_C_SOURCE 200112L
20+
1921 #include <string.h>
2022 #include <unistd.h>
2123
M main.c View
@@ -16,6 +16,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#define _POSIX_C_SOURCE 200112L
20+
1921 #include <stdlib.h>
2022 #include <stdio.h>
2123 #include <string.h>
@@ -430,8 +432,9 @@ int fncmp(const void *a, const void *b) {
430432 }
431433
432434 int main(int argc, char **argv) {
433− int i, len, start;
435+ int i, start;
434436 size_t n;
437+ ssize_t len;
435438 char *filename;
436439 struct stat fstats;
437440 r_dir_t dir;
@@ -460,11 +463,13 @@ int main(int argc, char **argv) {
460463 /* build file list: */
461464 if (options->from_stdin) {
462465 filename = NULL;
463− while ((len = getline(&filename, &n, stdin)) > 0) {
466+ while ((len = get_line(&filename, &n, stdin)) > 0) {
464467 if (filename[len-1] == '\n')
465468 filename[len-1] = '\0';
466469 check_add_file(filename);
467470 }
471+ if (filename)
472+ free(filename);
468473 } else {
469474 for (i = 0; i < options->filecnt; i++) {
470475 filename = options->filenames[i];
M options.c View
@@ -16,12 +16,12 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19−#define _POSIX_C_SOURCE 2 /* for getopt(3) */
20−#include <unistd.h>
19+#define _POSIX_C_SOURCE 200112L
2120
2221 #include <stdlib.h>
2322 #include <string.h>
2423 #include <stdio.h>
24+#include <unistd.h>
2525
2626 #include "options.h"
2727 #include "util.h"
M thumbs.c View
@@ -16,12 +16,14 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#define _POSIX_C_SOURCE 200112L
20+
1921 #include <stdlib.h>
2022 #include <string.h>
21−#include <sys/time.h>
2223 #include <sys/types.h>
2324 #include <sys/stat.h>
2425 #include <unistd.h>
26+#include <utime.h>
2527
2628 #include "thumbs.h"
2729 #include "util.h"
@@ -29,11 +31,6 @@
2931 #define _THUMBS_CONFIG
3032 #include "config.h"
3133
32−#ifdef __NetBSD__
33−#define st_mtim st_mtimespec
34−#define st_atim st_atimespec
35−#endif
36−
3734 #ifdef EXIF_SUPPORT
3835 void exif_auto_orientate(const fileinfo_t*);
3936 #endif
@@ -76,12 +73,8 @@ Imlib_Image* tns_cache_load(const char *filepath) {
7673 return NULL;
7774
7875 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)
8377 im = imlib_load_image(cfile);
84− }
8578 free(cfile);
8679 }
8780
@@ -91,7 +84,7 @@ Imlib_Image* tns_cache_load(const char *filepath) {
9184 void tns_cache_write(thumb_t *t, Bool force) {
9285 char *cfile, *dirend;
9386 struct stat cstats, fstats;
94− struct timeval times[2];
87+ struct utimbuf times;
9588 Imlib_Load_Error err = 0;
9689
9790 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) {
10194 return;
10295
10396 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) {
10898 if ((dirend = strrchr(cfile, '/'))) {
10999 *dirend = '\0';
110100 err = r_mkdir(cfile);
@@ -120,9 +110,9 @@ void tns_cache_write(thumb_t *t, Bool force) {
120110 if (err) {
121111 warn("could not cache thumbnail: %s", t->file->name);
122112 } else {
123− TIMESPEC_TO_TIMEVAL(&times[0], &fstats.st_atim);
124− TIMESPEC_TO_TIMEVAL(&times[1], &fstats.st_mtim);
125− utimes(cfile, times);
113+ times.actime = fstats.st_atime;
114+ times.modtime = fstats.st_mtime;
115+ utime(cfile, &times);
126116 }
127117 }
128118 free(cfile);
M util.c View
@@ -16,6 +16,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#define _POSIX_C_SOURCE 200112L
20+
1921 #include <stdlib.h>
2022 #include <string.h>
2123 #include <sys/types.h>
@@ -27,6 +29,7 @@
2729 #include "util.h"
2830
2931 enum {
32+ BUF_SIZE = 1024,
3033 DNAME_CNT = 512,
3134 FNAME_LEN = 1024
3235 };
@@ -87,6 +90,39 @@ void die(const char* fmt, ...) {
8790 exit(1);
8891 }
8992
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+
90126 void size_readable(float *size, const char **unit) {
91127 const char *units[] = { "", "K", "M", "G" };
92128 int i;
@@ -98,13 +134,9 @@ void size_readable(float *size, const char **unit) {
98134
99135 char* absolute_path(const char *filename) {
100136 size_t len;
101− char *path = NULL;
102137 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;
108140
109141 if (!filename || *filename == '\0' || *filename == '/')
110142 return NULL;
M util.h View
@@ -45,13 +45,6 @@
4545 (tv)->tv_usec += (t) % 1000 * 1000; \
4646 }
4747
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−
5548 typedef struct {
5649 DIR *dir;
5750 char *name;
@@ -69,6 +62,8 @@ char* s_strdup(char*);
6962 void warn(const char*, ...);
7063 void die(const char*, ...);
7164
65+ssize_t get_line(char**, size_t*, FILE*);
66+
7267 void size_readable(float*, const char**);
7368
7469 char* absolute_path(const char*);
M window.c View
@@ -16,6 +16,8 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#define _POSIX_C_SOURCE 200112L
20+
1921 #include <string.h>
2022 #include <X11/Xutil.h>
2123 #include <X11/cursorfont.h>