]> granicus.if.org Git - procps-ng/commitdiff
library: provide ref and unref for diskstat
authorCraig Small <csmall@enc.com.au>
Sun, 1 May 2016 06:15:49 +0000 (16:15 +1000)
committerCraig Small <csmall@enc.com.au>
Sun, 1 May 2016 06:15:49 +0000 (16:15 +1000)
While procps_diskstat_ref and procps_diskstat_unref were declared
they actually weren't implemented in the library. Linking some
binary that used these functions gave the following errors:

  CCLD     vmstat
vmstat.o: In function `disksum_format':
vmstat.c:719: undefined reference to `procps_diskstat_unref'
vmstat.o: In function `diskformat':
vmstat.c:591: undefined reference to `procps_diskstat_unref'

proc/diskstat.c

index 2b8409b04e6a6b6893618f66fba1046859abe7ba..bf2db0803a5f14875262186a231878e5ff7d0d32 100644 (file)
@@ -226,6 +226,29 @@ PROCPS_EXPORT int procps_diskstat_read (
     return 0;
 }
 
+PROCPS_EXPORT int procps_diskstat_ref (
+        struct procps_diskstat *info)
+{
+    if (info == NULL)
+        return -EINVAL;
+    info->refcount++;
+    return info->refcount;
+}
+
+PROCPS_EXPORT int procps_diskstat_unref (
+        struct procps_diskstat **info)
+{
+    if (info == NULL || *info == NULL)
+        return -EINVAL;
+    (*info)->refcount--;
+    if ((*info)->refcount == 0) {
+        free(*info);
+        *info = NULL;
+        return 0;
+    }
+    return (*info)->refcount;
+}
+
 /*
  * procps_diskstat_dev_count:
  *