system: make system functions return error on error

Return -errno from system functions instead of -1 in errors. This
makes it easier to pass along the result without having to go to
errno etc..
This commit is contained in:
Wim Taymans 2019-06-20 17:31:29 +02:00
parent 03eeb945f3
commit 5b7e95c71c
9 changed files with 154 additions and 157 deletions

View file

@ -277,7 +277,7 @@ static int client_node_demarshal_transport(void *object, const struct pw_protoco
readfd = pw_protocol_native_get_proxy_fd(proxy, ridx);
writefd = pw_protocol_native_get_proxy_fd(proxy, widx);
if (readfd == -1 || writefd == -1)
if (readfd < 0 || writefd < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, transport, 0, node_id,
@ -514,7 +514,7 @@ static int client_node_demarshal_set_activation(void *object, const struct pw_pr
return -EINVAL;
signalfd = pw_protocol_native_get_proxy_fd(proxy, sigidx);
if (signalfd == -1)
if (signalfd < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, set_activation, 0,

View file

@ -473,12 +473,10 @@ static int impl_steal_fd(struct pw_protocol_client *client)
return -EIO;
fd = dup(impl->source->fd);
if (fd == -1) {
fd = -errno;
goto out;
}
if (fd < 0)
return -errno;
pw_protocol_client_disconnect(client);
out:
return fd;
}

View file

@ -74,7 +74,7 @@ struct impl {
*
* \param conn the connection
* \param index the index of the fd to get
* \return the fd at \a index or -1 when no such fd exists
* \return the fd at \a index or -ENOENT when no such fd exists
*
* \memberof pw_protocol_native_connection
*/
@ -84,7 +84,7 @@ int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *c
struct buffer *buf = &impl->in;
if (index >= buf->msg.n_fds)
return -1;
return -ENOENT;
return buf->msg.fds[index];
}

View file

@ -40,7 +40,7 @@ static void test_create(struct pw_protocol_native_connection *conn)
spa_assert(msg != NULL);
res = pw_protocol_native_connection_get_fd(conn, 0);
spa_assert(res == -1);
spa_assert(res == -ENOENT);
res = pw_protocol_native_connection_flush(conn);
spa_assert(res == 0);
@ -94,8 +94,8 @@ static int read_message(struct pw_protocol_native_connection *conn)
spa_assert_not_reached();
fd = pw_protocol_native_connection_get_fd(conn, fdidx);
spa_assert(fd != -ENOENT);
pw_log_debug("got fd %d %d", fdidx, fd);
spa_assert(fd != -1);
return 0;
}