From: Daniel Elstner Date: Mon, 4 Jan 2016 17:53:30 +0000 (+0100) Subject: resource: Replace ssize_t with gssize to avoid unistd.h X-Git-Tag: libsigrok-0.4.0~39 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=32ba0d80054df01767ec323c621ab1c6bc5f310c;p=libsigrok.git resource: Replace ssize_t with gssize to avoid unistd.h --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 34edff87..4b4de2d3 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -101,7 +101,7 @@ SR_PRIV int ResourceReader::close_callback(struct sr_resource *res, return SR_OK; } -SR_PRIV ssize_t ResourceReader::read_callback(const struct sr_resource *res, +SR_PRIV gssize ResourceReader::read_callback(const struct sr_resource *res, void *buf, size_t count, void *cb_data) noexcept { try { diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index 1db6c7df..eb7957e5 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -232,7 +232,7 @@ private: const char *name, void *cb_data) noexcept; static SR_PRIV int close_callback(struct sr_resource *res, void *cb_data) noexcept; - static SR_PRIV ssize_t read_callback(const struct sr_resource *res, + static SR_PRIV gssize read_callback(const struct sr_resource *res, void *buf, size_t count, void *cb_data) noexcept; friend class Context; }; diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index ea9d4779..6ae3be8f 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -20,8 +20,6 @@ #ifndef LIBSIGROK_PROTO_H #define LIBSIGROK_PROTO_H -#include - /** * @file * @@ -208,7 +206,7 @@ typedef int (*sr_resource_open_callback)(struct sr_resource *res, const char *name, void *cb_data); typedef int (*sr_resource_close_callback)(struct sr_resource *res, void *cb_data); -typedef ssize_t (*sr_resource_read_callback)(const struct sr_resource *res, +typedef gssize (*sr_resource_read_callback)(const struct sr_resource *res, void *buf, size_t count, void *cb_data); SR_API int sr_resource_set_hooks(struct sr_context *ctx, diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index a045b57e..5ada5f99 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -868,7 +868,7 @@ SR_PRIV int sr_resource_open(struct sr_context *ctx, G_GNUC_WARN_UNUSED_RESULT; SR_PRIV int sr_resource_close(struct sr_context *ctx, struct sr_resource *res); -SR_PRIV ssize_t sr_resource_read(struct sr_context *ctx, +SR_PRIV gssize sr_resource_read(struct sr_context *ctx, const struct sr_resource *res, void *buf, size_t count) G_GNUC_WARN_UNUSED_RESULT; SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type, diff --git a/src/resource.c b/src/resource.c index 3a63a06a..b921d93d 100644 --- a/src/resource.c +++ b/src/resource.c @@ -173,7 +173,7 @@ static int resource_close_default(struct sr_resource *res, void *cb_data) return SR_OK; } -static ssize_t resource_read_default(const struct sr_resource *res, +static gssize resource_read_default(const struct sr_resource *res, void *buf, size_t count, void *cb_data) { FILE *file; @@ -186,7 +186,7 @@ static ssize_t resource_read_default(const struct sr_resource *res, sr_err("%s: invalid handle.", __func__); return SR_ERR_ARG; } - if (count > SSIZE_MAX) { + if (count > G_MAXSSIZE) { sr_err("%s: count %zu too large.", __func__, count); return SR_ERR_ARG; } @@ -309,10 +309,10 @@ SR_PRIV int sr_resource_close(struct sr_context *ctx, struct sr_resource *res) * * @private */ -SR_PRIV ssize_t sr_resource_read(struct sr_context *ctx, +SR_PRIV gssize sr_resource_read(struct sr_context *ctx, const struct sr_resource *res, void *buf, size_t count) { - ssize_t n_read; + gssize n_read; n_read = (*ctx->resource_read_cb)(res, buf, count, ctx->resource_cb_data); @@ -342,7 +342,7 @@ SR_PRIV void *sr_resource_load(struct sr_context *ctx, struct sr_resource res; void *buf; size_t res_size; - ssize_t n_read; + gssize n_read; if (sr_resource_open(ctx, &res, type, name) != SR_OK) return NULL;