catalog.c revision eb56eb9b40950f1edcffdb7313f8de4f8572a6d5
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2012 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
3c0cf502796be355431d4a64d738e75f543aa51dLennart Poetteringconst char * const catalog_file_dirs[] = {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define CATALOG_SIGNATURE (uint8_t[]) { 'R', 'H', 'H', 'H', 'K', 'S', 'L', 'P' }
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtstatic unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
const CatalogItem *i = p;
uint64_t u;
static int catalog_compare_func(const void *a, const void *b) {
const CatalogItem *i = a, *j = b;
static int finish_item(
Hashmap *h,
const char *language,
const char *payload) {
assert(h);
if (offset < 0)
return log_oom();
return log_oom();
if (language) {
r = hashmap_put(h, i, i);
if (r == -EEXIST) {
i = NULL;
if (!end)
beg --;
if (!_lang)
return -ENOMEM;
size_t c;
c = strlen(t);
return -EINVAL;
return -EINVAL;
if (deflang) {
if (!*lang)
return -ENOMEM;
assert(h);
return -errno;
size_t a, b, c;
if (feof(f))
return -errno;
if (line[0] == 0) {
empty_line = true;
if (empty_line &&
bool with_language;
if (got_id) {
if (with_language) {
got_id = true;
empty_line = false;
if (payload)
if (!got_id) {
return -EINVAL;
return log_oom();
if (empty_line) {
payload = t;
empty_line = false;
if (got_id) {
size_t k;
return log_oom();
database);
r = -EIO;
if (k != sizeof(header)) {
goto error;
if (k != n * sizeof(CatalogItem)) {
goto error;
goto error;
fflush(w);
if (ferror(w)) {
goto error;
r = -errno;
goto error;
return ftell(w);
unlink(p);
CatalogItem *i;
Iterator j;
if (!h || !sb) {
r = log_oom();
goto finish;
goto finish;
*f, strerror(-r));
goto finish;
if (hashmap_size(h) <= 0) {
goto finish;
if (!items) {
r = log_oom();
goto finish;
HASHMAP_FOREACH(i, h, j) {
items[n++] = *i;
if (sb)
const CatalogHeader *h;
int fd;
if (fd < 0)
return -errno;
return -errno;
return -EINVAL;
if (p == MAP_FAILED) {
return -errno;
h->incompatible_flags != 0 ||
st.st_size < (off_t) (le64toh(h->header_size) + le64toh(h->catalog_item_size) * le64toh(h->n_items))) {
return -EBADMSG;
*_p = p;
const CatalogHeader *h = p;
const char *loc;
f = bsearch(&key, (const uint8_t*) p + le64toh(h->header_size), le64toh(h->n_items), le64toh(h->catalog_item_size), catalog_compare_func);
f = bsearch(&key, (const uint8_t*) p + le64toh(h->header_size), le64toh(h->n_items), le64toh(h->catalog_item_size), catalog_compare_func);
f = bsearch(&key, (const uint8_t*) p + le64toh(h->header_size), le64toh(h->n_items), le64toh(h->catalog_item_size), catalog_compare_func);
return NULL;
void *p = NULL;
r = -ENOENT;
goto finish;
if (!text) {
r = -ENOMEM;
goto finish;
return NULL;
return NULL;
if (oneline) {
void *p = NULL;
const CatalogHeader *h;
bool last_id_set = false;
last_id_set = true;
char **item;
*item);