projects
/
apps
/
pfixtools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Strlist filter.
[apps/pfixtools.git]
/
common
/
tst-trie.c
diff --git
a/common/tst-trie.c
b/common/tst-trie.c
index
77fd208
..
990b151
100644
(file)
--- a/
common/tst-trie.c
+++ b/
common/tst-trie.c
@@
-33,49
+33,27
@@
* Copyright © 2008 Florent Bruneau
*/
* Copyright © 2008 Florent Bruneau
*/
-#include <arpa/inet.h>
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-
#include "common.h"
#include "str.h"
#include "trie.h"
#include "common.h"
#include "str.h"
#include "trie.h"
+#include "file.h"
static trie_t *create_trie_from_file(const char *file)
{
trie_t *db;
static trie_t *create_trie_from_file(const char *file)
{
trie_t *db;
- const char *map, *p, *end;
- struct stat st;
- int fd;
+ file_map_t map;
+ const char *p, *end;
char line[BUFSIZ];
char line[BUFSIZ];
- fd = open(file, O_RDONLY, 0000);
- if (fd < 0) {
- UNIXERR("open");
- return NULL;
- }
-
- if (fstat(fd, &st) < 0) {
- UNIXERR("fstat");
- close(fd);
+ if (!file_map_open(&map, file, false)) {
return NULL;
}
return NULL;
}
-
- p = map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (map == MAP_FAILED) {
- UNIXERR("mmap");
- close(fd);
- return NULL;
- }
- close(fd);
-
- end = map + st.st_size;
- while (end > map && end[-1] != '\n') {
+ p = map.map;
+ end = map.end;
+ while (end > p && end[-1] != '\n') {
--end;
}
--end;
}
- if (end != map
+ st.st_size
) {
+ if (end != map
.end
) {
syslog(LOG_WARNING, "file %s miss a final \\n, ignoring last line",
file);
}
syslog(LOG_WARNING, "file %s miss a final \\n, ignoring last line",
file);
}
@@
-102,7
+80,7
@@
static trie_t *create_trie_from_file(const char *file)
trie_insert(db, line);
p = eol + 1;
}
trie_insert(db, line);
p = eol + 1;
}
-
munmap((void*)map, st.st_size
);
+
file_map_close(&map
);
trie_compile(db, false);
return db;
}
trie_compile(db, false);
return db;
}
@@
-120,7
+98,7
@@
int main(int argc, char *argv[])
trie_insert(trie, "coucou chez vous");
trie_insert(trie, "debout !");
trie_compile(trie, false);
trie_insert(trie, "coucou chez vous");
trie_insert(trie, "debout !");
trie_compile(trie, false);
- trie_inspect(trie);
+ trie_inspect(trie
, true
);
#define ASSERT_TRUE(str) \
if (!trie_lookup(trie, str)) { \
#define ASSERT_TRUE(str) \
if (!trie_lookup(trie, str)) { \
@@
-151,7
+129,7
@@
int main(int argc, char *argv[])
*/
if (argc > 1) {
trie = create_trie_from_file(argv[1]);
*/
if (argc > 1) {
trie = create_trie_from_file(argv[1]);
-
// trie_inspect(tri
e);
+
trie_inspect(trie, fals
e);
trie_delete(&trie);
}
return 0;
trie_delete(&trie);
}
return 0;