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
79 | 79 |
src/showkey
|
80 | 80 |
src/spawn_console
|
81 | 81 |
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]
|
87 | 89 |
tests/libkeymap-bkeymap
|
88 | 90 |
tests/libkeymap-dumpkeys
|
89 | 91 |
tests/libkeymap-mktable
|
90 | 92 |
tests/libkeymap-showmaps
|
91 | |
tests/libkeymap-test*
|
92 | |
tests/test-suite.log
|
|
93 |
tests/libkeymap-test[0-9][0-9]
|
343 | 343 |
snprintf(fp->pathname, sizeof(fp->pathname), "%s/%s%s%s", dir, fnam, suf[index], (dc ? dc->ext : ""));
|
344 | 344 |
|
345 | 345 |
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;
|
360 | 353 |
}
|
361 | 354 |
}
|
362 | 355 |
|
|
456 | 449 |
|
457 | 450 |
return fp;
|
458 | 451 |
}
|
|
452 |
|
|
453 |
int
|
|
454 |
kbdfile_is_compressed(struct kbdfile *fp)
|
|
455 |
{
|
|
456 |
return (fp->flags & KBDFILE_PIPE);
|
|
457 |
}
|
44 | 44 |
FILE *kbdfile_get_file(struct kbdfile *fp);
|
45 | 45 |
int kbdfile_set_file(struct kbdfile *fp, FILE *x);
|
46 | 46 |
|
|
47 |
int kbdfile_is_compressed(struct kbdfile *fp);
|
|
48 |
|
47 | 49 |
#include <syslog.h>
|
48 | 50 |
|
49 | 51 |
void
|
65 | 65 |
libkbdfile-test10 \
|
66 | 66 |
libkbdfile-test11 \
|
67 | 67 |
libkbdfile-test12 \
|
|
68 |
libkbdfile-test13 \
|
68 | 69 |
libkeymap-test01 \
|
69 | 70 |
libkeymap-test02 \
|
70 | 71 |
libkeymap-test03 \
|
|
109 | 110 |
libkbdfile_test10_SOURCES = libkbdfile-test10.c
|
110 | 111 |
libkbdfile_test11_SOURCES = libkbdfile-test11.c
|
111 | 112 |
libkbdfile_test12_SOURCES = libkbdfile-test12.c
|
|
113 |
libkbdfile_test13_SOURCES = libkbdfile-test13.c
|
112 | 114 |
|
113 | 115 |
libkeymap_test01_SOURCES = libkeymap-test01.c
|
114 | 116 |
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 |
}
|