trying to port statvfs call to BSD
[oweals/gnunet.git] / src / util / os_load.c
index a25331effe5ab9e02f5b65d7a597bf5bf134a90c..e54147ff4ed2c5045898a2cffc91dea7dcaec855 100644 (file)
@@ -156,9 +156,10 @@ updateUsage ()
       unsigned long long usage_time = 0, total_time = 1;
 
       /* Get the first line with the data */
+      memset (line, 0, sizeof (line));
       rewind (proc_stat);
       fflush (proc_stat);
-      if (NULL == fgets (line, 256, proc_stat))
+      if (NULL == fgets (line, sizeof (line), proc_stat))
         {
           GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR |
                                     GNUNET_ERROR_TYPE_BULK,
@@ -603,6 +604,8 @@ GNUNET_OS_load_cpu_get (const struct GNUNET_CONFIGURATION_Handle *cfg)
       GNUNET_CONFIGURATION_get_value_number (cfg, "LOAD", "MAXCPULOAD",
                                              &maxCPULoad))
     return GNUNET_SYSERR;
+  if (maxCPULoad == 0)
+    return 100;
   return (100 * ret) / maxCPULoad;
 }
 
@@ -626,6 +629,8 @@ GNUNET_OS_load_disk_get (const struct GNUNET_CONFIGURATION_Handle *cfg)
       GNUNET_CONFIGURATION_get_value_number (cfg, "LOAD", "MAXIOLOAD",
                                              &maxIOLoad))
     return GNUNET_SYSERR;
+  if (maxIOLoad == 0)
+    return 100;
   return (100 * ret) / maxIOLoad;
 }