From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Lizardo <anderson.lizardo@openbossa.org>
Subject: [PATCH BlueZ 06/17] serial: Fix errno handling convention
Date: Wed, 16 Nov 2011 09:19:53 -0400 [thread overview]
Message-ID: <1321449604-4188-7-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1321449604-4188-1-git-send-email-anderson.lizardo@openbossa.org>
Variables which are assigned to the errno variable (usually called
"err") should be negative, and "-err" should be used where a positive
value is needed.
---
serial/port.c | 6 +++---
serial/proxy.c | 39 ++++++++++++++++++---------------------
2 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/serial/port.c b/serial/port.c
index fa302be..3b36d44 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -183,16 +183,16 @@ static int port_release(struct serial_port *port)
req.flags = (1 << RFCOMM_HANGUP_NOW);
if (ioctl(rfcomm_ctl, RFCOMMRELEASEDEV, &req) < 0) {
- err = errno;
+ err = -errno;
error("Can't release device %s: %s (%d)",
- port->dev, strerror(err), err);
+ port->dev, strerror(-err), -err);
}
g_free(port->dev);
port->dev = NULL;
port->id = -1;
close(rfcomm_ctl);
- return -err;
+ return err;
}
static void serial_port_free(void *data)
diff --git a/serial/proxy.c b/serial/proxy.c
index 371ad5f..736f690 100644
--- a/serial/proxy.c
+++ b/serial/proxy.c
@@ -289,19 +289,18 @@ static inline int unix_socket_connect(const char *address)
/* Unix socket */
sk = socket(AF_UNIX, SOCK_STREAM, 0);
if (sk < 0) {
- err = errno;
+ err = -errno;
error("Unix socket(%s) create failed: %s(%d)",
- address, strerror(err), err);
- return -err;
+ address, strerror(-err), -err);
+ return err;
}
if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- err = errno;
+ err = -errno;
error("Unix socket(%s) connect failed: %s(%d)",
- address, strerror(err), err);
+ address, strerror(-err), -err);
close(sk);
- errno = err;
- return -err;
+ return err;
}
return sk;
@@ -329,18 +328,17 @@ static int tcp_socket_connect(const char *address)
sk = socket(PF_INET, SOCK_STREAM, 0);
if (sk < 0) {
- err = errno;
+ err = -errno;
error("TCP socket(%s) create failed %s(%d)", address,
- strerror(err), err);
- return -err;
+ strerror(-err), -err);
+ return err;
}
if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- err = errno;
+ err = -errno;
error("TCP socket(%s) connect failed: %s(%d)",
- address, strerror(err), err);
+ address, strerror(-err), -err);
close(sk);
- errno = err;
- return -err;
+ return err;
}
return sk;
}
@@ -351,18 +349,17 @@ static inline int tty_open(const char *tty, struct termios *ti)
sk = open(tty, O_RDWR | O_NOCTTY);
if (sk < 0) {
- err = errno;
- error("Can't open TTY %s: %s(%d)", tty, strerror(err), err);
- return -err;
+ err = -errno;
+ error("Can't open TTY %s: %s(%d)", tty, strerror(-err), -err);
+ return err;
}
if (ti && tcsetattr(sk, TCSANOW, ti) < 0) {
- err = errno;
+ err = -errno;
error("Can't change serial settings: %s(%d)",
- strerror(err), err);
+ strerror(-err), -err);
close(sk);
- errno = err;
- return -err;
+ return err;
}
return sk;
--
1.7.0.4
next prev parent reply other threads:[~2011-11-16 13:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 13:19 [PATCH BlueZ 00/17] Fix errno handling convention Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 01/17] AVCTP: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 02/17] AVDTP: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 03/17] audio/IPC: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 04/17] audio/PCM: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 05/17] audio: " Anderson Lizardo
2011-11-16 13:19 ` Anderson Lizardo [this message]
2011-11-16 13:19 ` [PATCH BlueZ 07/17] hcitool: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 08/17] hciconfig: " Anderson Lizardo
2011-11-24 5:58 ` Regarding MAP status Jaganath
2011-11-16 13:19 ` [PATCH BlueZ 09/17] textfile: Fix errno handling convention Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 10/17] sdp-client: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 11/17] sap-u8500: " Anderson Lizardo
2011-11-16 13:19 ` [PATCH BlueZ 12/17] network: " Anderson Lizardo
2011-11-16 13:20 ` [PATCH BlueZ 13/17] input: " Anderson Lizardo
2011-11-16 13:20 ` [PATCH BlueZ 14/17] btio: " Anderson Lizardo
2011-11-16 13:20 ` [PATCH BlueZ 15/17] bccmd: Fix overwriting errno value Anderson Lizardo
2011-11-16 13:20 ` [PATCH BlueZ 16/17] csr_bcsp: Fix missing errno attribution Anderson Lizardo
2011-11-16 13:20 ` [PATCH BlueZ 17/17] Fix return value check for bt_audio_service_open() Anderson Lizardo
2011-11-17 11:58 ` [PATCH BlueZ 00/17] Fix errno handling convention Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321449604-4188-7-git-send-email-anderson.lizardo@openbossa.org \
--to=anderson.lizardo@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox