#include <string.h>
#include <unistd.h>
#include <stdarg.h>
+#include <stdbool.h>
#include "libevdev.h"
#include "libevdev-int.h"
if (!dev)
return NULL;
dev->fd = -1;
+ dev->initialized = false;
dev->num_slots = -1;
dev->current_slot = -1;
dev->grabbed = LIBEVDEV_UNGRAB;
LIBEVDEV_EXPORT int
libevdev_change_fd(struct libevdev *dev, int fd)
{
- if (dev->fd == -1) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -1;
}
int i;
char buf[256];
- if (dev->fd != -1) {
+ if (dev->initialized) {
log_bug("device already initialized.\n");
return -EBADF;
}
* Same with the valuators, really, but they may not change.
*/
+ dev->initialized = true;
out:
return rc ? -errno : 0;
}
{
int rc = LIBEVDEV_READ_STATUS_SUCCESS;
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
if (!(flags & (LIBEVDEV_READ_FLAG_NORMAL|LIBEVDEV_READ_FLAG_SYNC|LIBEVDEV_READ_FLAG_FORCE_SYNC))) {
log_bug("invalid flags %#x\n.\n", flags);
struct pollfd fds = { dev->fd, POLLIN, 0 };
int rc;
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
if (queue_num_elements(dev) != 0)
return 1;
{
int rc;
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
if (code > ABS_MAX)
return -EINVAL;
{
int rc = 0;
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
if (grab != LIBEVDEV_GRAB && grab != LIBEVDEV_UNGRAB) {
log_bug("invalid grab parameter %#x\n", grab);
int rc = 0;
size_t nleds = 0;
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
memset(ev, 0, sizeof(ev));
LIBEVDEV_EXPORT int
libevdev_set_clock_id(struct libevdev *dev, int clockid)
{
- if (dev->fd < 0) {
+ if (!dev->initialized) {
log_bug("device not initialized. call libevdev_set_fd() first\n");
return -EBADF;
- }
+ } else if (dev->fd < 0)
+ return -EBADF;
return ioctl(dev->fd, EVIOCSCLOCKID, &clockid) ? -errno : 0;
}