[PATCH libevdev 1/9] Use ENOMEM instead of ENOSPC

Peter Hutterer peter.hutterer at who-t.net
Tue Sep 3 00:07:39 PDT 2013


>From errno(3):
   ENOMEM          Not enough space (POSIX.1)
   ENOSPC          No space left on device (POSIX.1)

when we run out memory the reason is a failed malloc, for which ENOMEM
seems more appropriate.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev-int.h   | 4 ++--
 libevdev/libevdev.c       | 8 ++++----
 libevdev/libevdev.h       | 2 +-
 test/test-common-uinput.c | 2 +-
 test/test-int-queue.c     | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h
index 61c2454..dd38cc8 100644
--- a/libevdev/libevdev-int.h
+++ b/libevdev/libevdev-int.h
@@ -194,11 +194,11 @@ static inline int
 queue_alloc(struct libevdev *dev, size_t size)
 {
 	if (size == 0)
-		return -ENOSPC;
+		return -ENOMEM;
 
 	dev->queue = calloc(size, sizeof(struct input_event));
 	if (!dev->queue)
-		return -ENOSPC;
+		return -ENOMEM;
 
 	dev->queue_size = size;
 	dev->queue_next = 0;
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 36160f6..436f7a9 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -89,7 +89,7 @@ libevdev_new_from_fd(int fd, struct libevdev **dev)
 
 	d = libevdev_new();
 	if (!d)
-		return -ENOSPC;
+		return -ENOMEM;
 
 	rc = libevdev_set_fd(d, fd);
 	if (rc < 0)
@@ -152,7 +152,7 @@ libevdev_set_fd(struct libevdev* dev, int fd)
 	free(dev->name);
 	dev->name = strdup(buf);
 	if (!dev->name) {
-		errno = ENOSPC;
+		errno = ENOMEM;
 		goto out;
 	}
 
@@ -167,7 +167,7 @@ libevdev_set_fd(struct libevdev* dev, int fd)
 	} else {
 		dev->phys = strdup(buf);
 		if (!dev->phys) {
-			errno = ENOSPC;
+			errno = ENOMEM;
 			goto out;
 		}
 	}
@@ -182,7 +182,7 @@ libevdev_set_fd(struct libevdev* dev, int fd)
 	} else  {
 		dev->uniq = strdup(buf);
 		if (!dev->uniq) {
-			errno = ENOSPC;
+			errno = ENOMEM;
 			goto out;
 		}
 	}
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index ff423b9..43b768d 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -202,7 +202,7 @@ extern "C" {
  *
  * dev = libevdev_new();
  * if (!dev)
- *         return ENOSPC;
+ *         return ENOMEM;
  *
  * err = libevdev_set_fd(dev, fd);
  * if (err < 0) {
diff --git a/test/test-common-uinput.c b/test/test-common-uinput.c
index 7f3fe1f..32ecb89 100644
--- a/test/test-common-uinput.c
+++ b/test/test-common-uinput.c
@@ -75,7 +75,7 @@ uinput_device_new_with_events_v(struct uinput_device **d, const char *name, cons
 
 	dev = uinput_device_new(name);
 	if (!dev)
-		return -ENOSPC;
+		return -ENOMEM;
 	if (id != DEFAULT_IDS)
 		uinput_device_set_ids(dev, id);
 
diff --git a/test/test-int-queue.c b/test/test-int-queue.c
index e809048..a57eb93 100644
--- a/test/test-int-queue.c
+++ b/test/test-int-queue.c
@@ -34,10 +34,10 @@ START_TEST(test_queue_alloc)
 	int rc;
 
 	rc = queue_alloc(&dev, 0);
-	ck_assert_int_eq(rc, -ENOSPC);
+	ck_assert_int_eq(rc, -ENOMEM);
 
 	rc = queue_alloc(&dev, ULONG_MAX);
-	ck_assert_int_eq(rc, -ENOSPC);
+	ck_assert_int_eq(rc, -ENOMEM);
 
 	rc = queue_alloc(&dev, 100);
 	ck_assert_int_eq(rc, 0);
-- 
1.8.2.1



More information about the Input-tools mailing list