3 * This file is part of kbd project.
4 * Copyright (C) 2014 Alexey Gladkov <gladkov.alexey@gmail.com>
6 * This file is covered by the GNU General Public License,
7 * which should be included with kbd as the file COPYING.
16 #include "libcommon.h"
19 int lk_func_exists(struct lk_ctx *ctx, int index)
21 return (lk_array_get_ptr(ctx->func_table, index) != NULL);
24 int lk_get_func(struct lk_ctx *ctx, struct kbsentry *kbs)
28 s = lk_array_get_ptr(ctx->func_table, kbs->kb_func);
30 ERR(ctx, _("func %d not allocated"), kbs->kb_func);
34 strncpy((char *)kbs->kb_string, s, sizeof(kbs->kb_string));
35 kbs->kb_string[sizeof(kbs->kb_string) - 1] = 0;
40 int lk_add_func(struct lk_ctx *ctx, struct kbsentry *kbs)
44 s = lk_array_get_ptr(ctx->func_table, kbs->kb_func);
48 s = strdup((char *)kbs->kb_string);
50 if (lk_array_set(ctx->func_table, kbs->kb_func, &s) < 0) {
52 ERR(ctx, _("out of memory"));
59 int lk_del_func(struct lk_ctx *ctx, int index)
61 if (lk_array_unset(ctx->func_table, index) < 0) {
62 ERR(ctx, _("Unable to remove item from the list of functions"));