From dde5b23665ba3b29ccfa8c9fd640c5995de3b4a3 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 9 Aug 2012 17:29:01 -0300 Subject: [PATCH] rfcomm: Fix checking return value instead of errno We were checking by a positive return value instead of checking by -1 and errno. However when there's no support for TTY kernel returns EOPNOTSUPP as usual, which in the end will have a return value of -1 and errno will be set to EOPNOTSUPP. --- tools/rfcomm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/rfcomm.c b/tools/rfcomm.c index e73b0ba9b..0a8067021 100644 --- a/tools/rfcomm.c +++ b/tools/rfcomm.c @@ -182,10 +182,14 @@ static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int ar } err = ioctl(ctl, RFCOMMCREATEDEV, &req); - if (err == EOPNOTSUPP) - fprintf(stderr, "RFCOMM TTY support not available\n"); - else if (err < 0) - perror("Can't create device"); + if (err == -1) { + err = -errno; + + if (err == -EOPNOTSUPP) + fprintf(stderr, "RFCOMM TTY support not available\n"); + else + perror("Can't create device"); + } return err; } -- 2.47.3