From c3fee331d5dd4784c7a793f5a63853101e1ceee3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jan 2015 23:14:45 +0000 Subject: -make sure we get the correct errno back after GNUNET_NETWORK_socket_create() --- src/util/configuration.c | 3 ++- src/util/disk.c | 20 ++++++++++++-------- src/util/network.c | 11 +++++------ src/util/service.c | 11 ++++++----- 4 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/util/configuration.c b/src/util/configuration.c index 9b68513af..3e6710543 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -346,7 +346,8 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, if (fs != GNUNET_DISK_fn_read (fn, mem, fs)) { LOG (GNUNET_ERROR_TYPE_WARNING, - "Error while reading file %s\n", fn); + "Error while reading file %s\n", + fn); GNUNET_free (fn); GNUNET_free (mem); return GNUNET_SYSERR; diff --git a/src/util/disk.c b/src/util/disk.c index c5a1b82c7..063ffc946 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -939,7 +939,9 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, return GNUNET_SYSERR; } } - LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes\n", bytes_read); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Read %u bytes\n", + bytes_read); } else { @@ -982,8 +984,10 @@ GNUNET_DISK_fn_read (const char *fn, struct GNUNET_DISK_FileHandle *fh; ssize_t ret; - fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); - if (!fh) + fh = GNUNET_DISK_file_open (fn, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); + if (NULL == fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_read (fh, result, len); GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); @@ -1196,7 +1200,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, unsigned int name_len; unsigned int n_size; - GNUNET_assert (dir_name != NULL); + GNUNET_assert (NULL != dir_name); dname = GNUNET_STRINGS_filename_expand (dir_name); if (dname == NULL) return GNUNET_SYSERR; @@ -1208,7 +1212,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_free (dname); return GNUNET_SYSERR; } - if (!S_ISDIR (istat.st_mode)) + if (! S_ISDIR (istat.st_mode)) { LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"), @@ -1218,7 +1222,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, } errno = 0; dinfo = OPENDIR (dname); - if ((errno == EACCES) || (dinfo == NULL)) + if ((errno == EACCES) || (NULL == dinfo)) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "opendir", dname); if (dinfo != NULL) @@ -1229,12 +1233,12 @@ GNUNET_DISK_directory_scan (const char *dir_name, name_len = 256; n_size = strlen (dname) + name_len + 2; name = GNUNET_malloc (n_size); - while ((finfo = READDIR (dinfo)) != NULL) + while (NULL != (finfo = READDIR (dinfo))) { if ((0 == strcmp (finfo->d_name, ".")) || (0 == strcmp (finfo->d_name, ".."))) continue; - if (callback != NULL) + if (NULL != callback) { if (name_len < strlen (finfo->d_name)) { diff --git a/src/util/network.c b/src/util/network.c index 968870def..79c25c4d0 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -931,14 +931,13 @@ GNUNET_NETWORK_socket_create (int domain, int protocol) { struct GNUNET_NETWORK_Handle *ret; + int fd; - ret = GNUNET_new (struct GNUNET_NETWORK_Handle); - ret->fd = socket (domain, type, protocol); - if (-1 == ret->fd) - { - GNUNET_free (ret); + fd = socket (domain, type, protocol); + if (-1 == fd) return NULL; - } + ret = GNUNET_new (struct GNUNET_NETWORK_Handle); + ret->fd = fd; if (GNUNET_OK != initialize_network_handle (ret, domain, diff --git a/src/util/service.c b/src/util/service.c index d49ad4f2a..1f8532211 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -549,7 +549,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, else disablev6 = GNUNET_NO; - if (!disablev6) + if (! disablev6) { /* probe IPv6 support */ desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); @@ -562,8 +562,7 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, return GNUNET_SYSERR; } LOG (GNUNET_ERROR_TYPE_INFO, - _ - ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), + _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), service_name, STRERROR (errno)); disablev6 = GNUNET_YES; } @@ -623,7 +622,8 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, (unsigned long long) sizeof (s_un.sun_path)); unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); LOG (GNUNET_ERROR_TYPE_INFO, - _("Using `%s' instead\n"), unixpath); + _("Using `%s' instead\n"), + unixpath); } #ifdef LINUX abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, @@ -654,7 +654,8 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, } LOG (GNUNET_ERROR_TYPE_INFO, _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), - service_name, STRERROR (errno)); + service_name, + STRERROR (errno)); GNUNET_free (unixpath); unixpath = NULL; } -- cgit v1.2.3