aboutsummaryrefslogtreecommitdiffstats
path: root/main/kbd/0001-libkbdfile-Check-compression-suffix-even-if-the-suff.patch
blob: f3e8628af00e27ddcfdc5cd31da52021fed3bdba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 7e27102b6fc6991a6a4eca422b513781a26b1639 Mon Sep 17 00:00:00 2001
From: Alexey Gladkov <gladkov.alexey@gmail.com>
Date: Wed, 21 Aug 2019 13:29:16 +0200
Subject: [PATCH] libkbdfile: Check compression suffix even if the suffix is
 part of filename

Link: https://github.com/legionus/kbd/issues/32

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 src/libkbdfile/kbdfile.c | 25 ++++++++++++-------------
 src/libkbdfile/kbdfile.h |  2 ++
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/libkbdfile/kbdfile.c b/src/libkbdfile/kbdfile.c
index fb8e035..487b434 100644
--- a/src/libkbdfile/kbdfile.c
+++ b/src/libkbdfile/kbdfile.c
@@ -344,20 +344,13 @@ StartScan:
 		snprintf(fp->pathname, sizeof(fp->pathname), "%s/%s%s%s", dir, fnam, suf[index], (dc ? dc->ext : ""));
 
 		if (!dc) {
-			fp->flags &= ~KBDFILE_PIPE;
-			fp->fd = fopen(fp->pathname, "r");
+			rc = maybe_pipe_open(fp);
+			goto EndScan;
+		}
 
-			if (!(fp->fd)) {
-				strerror_r(errno, errbuf, sizeof(errbuf));
-				ERR(fp->ctx, "fopen: %s: %s", fp->pathname, errbuf);
-				rc = -1;
-				goto EndScan;
-			}
-		} else {
-			if (pipe_open(dc, fp) < 0) {
-				rc = -1;
-				goto EndScan;
-			}
+		if (pipe_open(dc, fp) < 0) {
+			rc = -1;
+			goto EndScan;
 		}
 	}
 
@@ -457,3 +450,9 @@ kbdfile_open(struct kbdfile_ctx *ctx, const char *filename)
 
 	return fp;
 }
+
+int
+kbdfile_is_compressed(struct kbdfile *fp)
+{
+	return (fp->flags & KBDFILE_PIPE);
+}
diff --git a/src/libkbdfile/kbdfile.h b/src/libkbdfile/kbdfile.h
index 412179a..0318a8e 100644
--- a/src/libkbdfile/kbdfile.h
+++ b/src/libkbdfile/kbdfile.h
@@ -45,6 +45,8 @@ int kbdfile_set_pathname(struct kbdfile *fp, const char *pathname);
 FILE *kbdfile_get_file(struct kbdfile *fp);
 int kbdfile_set_file(struct kbdfile *fp, FILE *x);
 
+int kbdfile_is_compressed(struct kbdfile *fp);
+
 #include <syslog.h>
 
 void