Codebase list kbd / 7e27102
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> Alexey Gladkov 4 years ago
8 changed file(s) with 64 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
7979 src/showkey
8080 src/spawn_console
8181 src/spawn_login
82 tests/alt-is-meta*
83 tests/dumpkeys-bkeymap*
84 tests/dumpkeys-fulltable*
85 tests/dumpkeys-mktable*
86 tests/libkbdfile-test*
82 tests/*.log
83 tests/*.trs
84 tests/alt-is-meta
85 tests/dumpkeys-bkeymap
86 tests/dumpkeys-fulltable
87 tests/dumpkeys-mktable
88 tests/libkbdfile-test[0-9][0-9]
8789 tests/libkeymap-bkeymap
8890 tests/libkeymap-dumpkeys
8991 tests/libkeymap-mktable
9092 tests/libkeymap-showmaps
91 tests/libkeymap-test*
92 tests/test-suite.log
93 tests/libkeymap-test[0-9][0-9]
343343 snprintf(fp->pathname, sizeof(fp->pathname), "%s/%s%s%s", dir, fnam, suf[index], (dc ? dc->ext : ""));
344344
345345 if (!dc) {
346 fp->flags &= ~KBDFILE_PIPE;
347 fp->fd = fopen(fp->pathname, "r");
348
349 if (!(fp->fd)) {
350 strerror_r(errno, errbuf, sizeof(errbuf));
351 ERR(fp->ctx, "fopen: %s: %s", fp->pathname, errbuf);
352 rc = -1;
353 goto EndScan;
354 }
355 } else {
356 if (pipe_open(dc, fp) < 0) {
357 rc = -1;
358 goto EndScan;
359 }
346 rc = maybe_pipe_open(fp);
347 goto EndScan;
348 }
349
350 if (pipe_open(dc, fp) < 0) {
351 rc = -1;
352 goto EndScan;
360353 }
361354 }
362355
456449
457450 return fp;
458451 }
452
453 int
454 kbdfile_is_compressed(struct kbdfile *fp)
455 {
456 return (fp->flags & KBDFILE_PIPE);
457 }
4444 FILE *kbdfile_get_file(struct kbdfile *fp);
4545 int kbdfile_set_file(struct kbdfile *fp, FILE *x);
4646
47 int kbdfile_is_compressed(struct kbdfile *fp);
48
4749 #include <syslog.h>
4850
4951 void
6565 libkbdfile-test10 \
6666 libkbdfile-test11 \
6767 libkbdfile-test12 \
68 libkbdfile-test13 \
6869 libkeymap-test01 \
6970 libkeymap-test02 \
7071 libkeymap-test03 \
109110 libkbdfile_test10_SOURCES = libkbdfile-test10.c
110111 libkbdfile_test11_SOURCES = libkbdfile-test11.c
111112 libkbdfile_test12_SOURCES = libkbdfile-test12.c
113 libkbdfile_test13_SOURCES = libkbdfile-test13.c
112114
113115 libkeymap_test01_SOURCES = libkeymap-test01.c
114116 libkeymap_test02_SOURCES = libkeymap-test02.c
0 #include <stdio.h>
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4
5 #include <kbdfile.h>
6 #include "libcommon.h"
7
8 int
9 main(int __attribute__((unused)) argc, char **argv)
10 {
11 set_progname(argv[0]);
12
13 struct kbdfile *fp = kbdfile_new(NULL);
14 if (!fp)
15 kbd_error(EXIT_FAILURE, 0, "unable to create kbdfile");
16
17 const char *const dirpath[] = { "", DATADIR "/findfile/test_1/consolefonts/", 0 };
18 const char *const suffixes[] = { "", ".psfu", ".psf", ".cp", ".fnt", 0 };
19
20 const char *expect = DATADIR "/findfile/test_1/consolefonts/simple-1.psf.gz";
21
22 int rc = 0;
23
24 rc = kbdfile_find((char *)"simple-1.psf.gz", (char **) dirpath, (char **) suffixes, fp);
25
26 if (rc != 0)
27 kbd_error(EXIT_FAILURE, 0, "unable to find file");
28
29 if (strcmp(expect, kbdfile_get_pathname(fp)) != 0)
30 kbd_error(EXIT_FAILURE, 0, "unexpected file: %s (expected %s)", kbdfile_get_pathname(fp), expect);
31
32 if (!kbdfile_is_compressed(fp))
33 kbd_error(EXIT_FAILURE, 0, "not compressed: %s\n", kbdfile_get_pathname(fp));
34
35 kbdfile_free(fp);
36
37 return EXIT_SUCCESS;
38 }