#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
#include <xkbcommon/xkbcommon-names.h>
#include <xkbcommon/xkbcommon-keysyms.h>
/**
* Creates an XKB keymap from a full text XKB keymap passed into the
- * file descriptor.
+ * file.
*/
struct xkb_keymap *
-xkb_map_new_from_fd(struct xkb_context *context,
- int fd, enum xkb_keymap_format format,
+xkb_map_new_from_file(struct xkb_context *context,
+ FILE *file, enum xkb_keymap_format format,
enum xkb_map_compile_flags flags);
/**
}
_X_EXPORT struct xkb_keymap *
-xkb_map_new_from_fd(struct xkb_context *ctx,
- int fd,
- enum xkb_keymap_format format,
- enum xkb_map_compile_flags flags)
+xkb_map_new_from_file(struct xkb_context *ctx,
+ FILE *file,
+ enum xkb_keymap_format format,
+ enum xkb_map_compile_flags flags)
{
- XkbFile *file;
- FILE *fptr;
+ XkbFile *xkb_file;
if (format != XKB_KEYMAP_FORMAT_TEXT_V1) {
ERROR("unsupported keymap format %d\n", format);
return NULL;
}
- if (fd < 0) {
+ if (!file) {
ERROR("no file specified to generate XKB keymap\n");
- return NULL;
- }
-
- fptr = fdopen(fd, "r");
- if (!fptr) {
- ERROR("couldn't associate fd with file pointer\n");
return NULL;
}
- if (!XKBParseFile(ctx, fptr, "(unknown file)", &file)) {
+ if (!XKBParseFile(ctx, file, "(unknown file)", &xkb_file)) {
ERROR("failed to parse input xkb file\n");
return NULL;
}
- return compile_keymap(ctx, file);
+ return compile_keymap(ctx, xkb_file);
}
_X_EXPORT struct xkb_keymap *
*/
#include <assert.h>
-#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <fcntl.h>
#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include "xkbcommon/xkbcommon.h"
static int
test_file(const char *path)
{
- int fd;
+ FILE *file;
struct xkb_context *context;
struct xkb_keymap *keymap;
- fd = open(path, O_RDONLY);
- assert(fd >= 0);
+ file = fopen(path, "r");
+ assert(file != NULL);
context = xkb_context_new(0);
assert(context);
fprintf(stderr, "\nCompiling path: %s\n", path);
- keymap = xkb_map_new_from_fd(context, fd, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
- close(fd);
+ keymap = xkb_map_new_from_file(context, file,
+ XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+ fclose(file);
if (!keymap) {
fprintf(stderr, "Failed to compile keymap\n");