NAMESTORE/JSON: fix parsing exp and flags
[oweals/gnunet.git] / src / nse / gnunet-nse-profiler.c
index ea28bf61017ae85eb38e8334fd7b9a7758e75c23..a6b847f3a1514102bd8f37315414ca665ae63b40 100644 (file)
@@ -2,20 +2,20 @@
      This file is part of GNUnet.
      Copyright (C) 2011, 2012 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 /**
  * @file nse/gnunet-nse-profiler.c
@@ -374,13 +374,14 @@ nse_disconnect_adapter (void *cls,
  */
 static int
 stat_iterator (void *cls,
-              const char *subsystem,
-              const char *name,
-              uint64_t value, int is_persistent)
+               const char *subsystem,
+               const char *name,
+               uint64_t value,
+               int is_persistent)
 {
   char *output_buffer;
   struct GNUNET_TIME_Absolute now;
-  size_t size;
+  int size;
   unsigned int flag;
 
   GNUNET_assert (NULL != data_file);
@@ -390,8 +391,14 @@ stat_iterator (void *cls,
     flag = 1;
   size = GNUNET_asprintf (&output_buffer, "%llu %llu %u\n",
                           now.abs_value_us / 1000LL / 1000LL,
-                         value, flag);
-  if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
+                          value, flag);
+  if (0 > size)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Error formatting output buffer.\n");
+    GNUNET_free (output_buffer);
+    return GNUNET_SYSERR;
+  }
+  if (size != GNUNET_DISK_file_write (data_file, output_buffer, (size_t) size))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
     GNUNET_free (output_buffer);
@@ -836,42 +843,42 @@ int
 main (int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_SET_UINT ('C',
+    GNUNET_GETOPT_option_uint ('C',
                                    "connections",
                                    "COUNT",
                                    gettext_noop ("limit to the number of connections to NSE services, 0 for none"),
                                    &connection_limit),
-    GNUNET_GETOPT_OPTION_STRING ('d',
+    GNUNET_GETOPT_option_string ('d',
                                  "details",
                                  "FILENAME",
                                  gettext_noop ("name of the file for writing connection information and statistics"),
                                  &data_filename),
 
-    GNUNET_GETOPT_OPTION_STRING ('H',
+    GNUNET_GETOPT_option_string ('H',
                                  "hosts",
                                  "FILENAME",
                                  gettext_noop ("name of the file with the login information for the testbed"),
                                  &hosts_file),
 
-    GNUNET_GETOPT_OPTION_STRING ('o',
+    GNUNET_GETOPT_option_string ('o',
                                  "output",
                                  "FILENAME",
                                  gettext_noop ("name of the file for writing the main results"),
                                  &output_filename),
 
 
-    GNUNET_GETOPT_OPTION_STRING ('p',
+    GNUNET_GETOPT_option_string ('p',
                                  "peers",
                                  "NETWORKSIZESPEC",
                                  gettext_noop ("Number of peers to run in each round, separated by commas"),
                                  &num_peer_spec),
 
-    GNUNET_GETOPT_OPTION_INCREMENT_VALUE ('V',
+    GNUNET_GETOPT_option_increment_uint ('V',
                                           "verbose",
                                           gettext_noop ("be verbose (print progress information)"),
                                           &verbose),
 
-    GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME ('w',
+    GNUNET_GETOPT_option_relative_time ('w',
                                             "wait",
                                             "DELAY",
                                             gettext_noop ("delay between rounds"),