Krolyxon
Commit 66c3c55

Branches

Refs →

nsxiv66c3c55

Use POSIX.1-2008 getline(3)

Author
Bert Münnich
Date
2015-10-28 21:50 +0100
Parent
e574a6d
Commit
66c3c55759a7ee23af75657215a2fd0e1aa39558

+6 −37

4 files changed

  1. M Makefile +1 −1
  2. M main.c +5 −4
  3. M util.c +0 −30
  4. M util.h +0 −2
M Makefile View
@@ -5,7 +5,7 @@ MANPREFIX := $(PREFIX)/share/man
55
66 CC ?= gcc
77 CFLAGS += -std=c99 -Wall -pedantic
8−CPPFLAGS += -I$(PREFIX)/include -D_XOPEN_SOURCE=500
8+CPPFLAGS += -I$(PREFIX)/include -D_XOPEN_SOURCE=700
99 LDFLAGS += -L$(PREFIX)/lib
1010 LIBS := -lX11 -lImlib2
1111
M main.c View
@@ -825,8 +825,9 @@ int main(int argc, char **argv)
825825 fileidx = 0;
826826
827827 if (options->from_stdin) {
828+ n = 0;
828829 filename = NULL;
829− while ((len = get_line(&filename, &n, stdin)) > 0) {
830+ while ((len = getline(&filename, &n, stdin)) > 0) {
830831 if (filename[len-1] == '\n')
831832 filename[len-1] = '\0';
832833 check_add_file(filename, true);
@@ -883,9 +884,9 @@ int main(int argc, char **argv)
883884 const char *name[] = { "image-info", "key-handler" };
884885
885886 for (i = 0; i < ARRLEN(cmd); i++) {
886− len = strlen(homedir) + strlen(dsuffix) + strlen(name[i]) + 12;
887− *cmd[i] = (char*) s_malloc(len);
888− snprintf(*cmd[i], len, "%s%s/sxiv/exec/%s", homedir, dsuffix, name[i]);
887+ n = strlen(homedir) + strlen(dsuffix) + strlen(name[i]) + 12;
888+ *cmd[i] = (char*) s_malloc(n);
889+ snprintf(*cmd[i], n, "%s%s/sxiv/exec/%s", homedir, dsuffix, name[i]);
889890 if (access(*cmd[i], X_OK) != 0) {
890891 free(*cmd[i]);
891892 *cmd[i] = NULL;
M util.c View
@@ -96,36 +96,6 @@ void die(const char* fmt, ...)
9696 exit(EXIT_FAILURE);
9797 }
9898
99−ssize_t get_line(char **buf, size_t *n, FILE *stream)
100−{
101− size_t len;
102− char *s;
103−
104− if (*buf == NULL || *n == 0) {
105− *n = BUF_SIZE;
106− *buf = (char*) s_malloc(*n);
107− }
108− s = *buf;
109−
110− while (true) {
111− if (fgets(s, *n - (s - *buf), stream) == NULL)
112− return -1;
113− len = strlen(s);
114− if (feof(stream))
115− break;
116− if (len > 0 && s[len-1] == '\n')
117− break;
118− if (len + 1 == *n - (s - *buf)) {
119− *buf = (char*) s_realloc(*buf, 2 * *n);
120− s = *buf + *n - 1;
121− *n *= 2;
122− } else {
123− s += len;
124− }
125− }
126− return s - *buf + len;
127−}
128−
12999 void size_readable(float *size, const char **unit)
130100 {
131101 const char *units[] = { "", "K", "M", "G" };
M util.h View
@@ -68,8 +68,6 @@ char* s_strdup(const char*);
6868 void warn(const char*, ...);
6969 void die(const char*, ...);
7070
71−ssize_t get_line(char**, size_t*, FILE*);
72−
7371 void size_readable(float*, const char**);
7472
7573 char* absolute_path(const char*);