From: Guus Sliepen Date: Fri, 4 Oct 2019 14:55:48 +0000 (+0200) Subject: Have meshlink_get_node() and _submesh() set MESHLINK_ENOENT when appropriate. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=1dff8bd48588b90d7595b61bbb3594ba8ce1cb20;p=meshlink Have meshlink_get_node() and _submesh() set MESHLINK_ENOENT when appropriate. These functions can return NULL both when the parameters are invalid or if the node or submesh does not exist, meshlink_errno must be set correctly to distinguish between the two cases. --- diff --git a/src/meshlink.c b/src/meshlink.c index 90d64648..bee8eee3 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1857,6 +1857,11 @@ meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { pthread_mutex_lock(&(mesh->mesh_mutex)); node = (meshlink_node_t *)lookup_node(mesh, (char *)name); // TODO: make lookup_node() use const pthread_mutex_unlock(&(mesh->mesh_mutex)); + + if(!node) { + meshlink_errno = MESHLINK_ENOENT; + } + return node; } @@ -1871,6 +1876,11 @@ meshlink_submesh_t *meshlink_get_submesh(meshlink_handle_t *mesh, const char *na pthread_mutex_lock(&(mesh->mesh_mutex)); submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name); pthread_mutex_unlock(&(mesh->mesh_mutex)); + + if(!submesh) { + meshlink_errno = MESHLINK_ENOENT; + } + return submesh; }