From: Guus Sliepen Date: Sat, 19 Apr 2014 14:33:29 +0000 (+0200) Subject: No global variables: move meshlink_errno and _errstr to meshlink_handle_t. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=ae2beb99a42825d3b4fb77c15abfc8bad9bf0923;hp=5a7627ddb41361847ce39be96dafedcb3c87f27c No global variables: move meshlink_errno and _errstr to meshlink_handle_t. --- diff --git a/examples/chat.c b/examples/chat.c index 36ffd6b1..78f9eb27 100644 --- a/examples/chat.c +++ b/examples/chat.c @@ -39,7 +39,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { invitation = meshlink_invite(mesh, arg); if(!invitation) { - fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_errstr); + fprintf(stderr, "Could not invite '%s': %s\n", arg, mesh->errstr); return; } @@ -52,7 +52,7 @@ static void parse_command(meshlink_handle_t *mesh, char *buf) { } if(!meshlink_join(mesh, arg)) - fprintf(stderr, "Could not join using invitation: %s\n", meshlink_errstr); + fprintf(stderr, "Could not join using invitation: %s\n", mesh->errstr); else fprintf(stderr, "Invitation accepted!\n"); } else if(!strcasecmp(buf, "kick")) { @@ -129,7 +129,7 @@ static void parse_input(meshlink_handle_t *mesh, char *buf) { } if(!meshlink_send(mesh, destination, msg, strlen(msg) + 1)) { - fprintf(stderr, "Could not send message to '%s': %s\n", destination->name, meshlink_errstr); + fprintf(stderr, "Could not send message to '%s': %s\n", destination->name, mesh->errstr); return; } @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) { meshlink_handle_t *mesh = meshlink_open(confbase, nick); if(!mesh) { - fprintf(stderr, "Could not open MeshLink: %s\n", meshlink_errstr); + fprintf(stderr, "Could not open MeshLink: %s\n", mesh->errstr); return 1; } @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) { meshlink_set_log_cb(mesh, MESHLINK_INFO, log); if(!meshlink_start(mesh)) { - fprintf(stderr, "Could not start MeshLink: %s\n", meshlink_errstr); + fprintf(stderr, "Could not start MeshLink: %s\n", mesh->errstr); return 1; } diff --git a/src/meshlink.h b/src/meshlink.h index 42435849..dcafc3bc 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -26,17 +26,8 @@ /// A handle for an instance of MeshLink. typedef struct meshlink_handle meshlink_handle_t; -typedef struct meshlink_node meshlink_node_t; - -#ifndef MESHLINK_INTERNAL_H - /// A handle for a MeshLink node. -typedef struct meshlink_node { - const char *name; // Textual name of this node. - void *priv; // Private pointer which the application can set at will. -} meshlink_node_t; - -#endif // MESHLINK_INTERNAL_H +typedef struct meshlink_node meshlink_node_t; /// Code of most recent error encountered. typedef enum { @@ -45,10 +36,19 @@ typedef enum { MESHLINK_ENOENT, // Node is not known } meshlink_errno_t; -extern meshlink_errno_t meshlink_errno; +#ifndef MESHLINK_INTERNAL_H + +struct meshlink_handle { + meshlink_errno_t errno; /// Code of the last encountered error. + const char *errstr; /// Textual representation of most recent error encountered. +}; -/// Textual representation of most recent error encountered. -const char *meshlink_errstr; +struct meshlink_node { + const char *name; // Textual name of this node. + void *priv; // Private pointer which the application can set at will. +}; + +#endif // MESHLINK_INTERNAL_H /// Get the text for the given MeshLink error code. /** This function returns a pointer to the string containing the description of the given error code.