Constify tv_* functions
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 29 May 2014 17:59:01 +0000 (17:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 29 May 2014 17:59:01 +0000 (17:59 +0000)
* defs.h (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_mul, tv_div): Add
const qualifier to read only arguments.
* util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_mul, tv_div):
Likewise.

defs.h
util.c

diff --git a/defs.h b/defs.h
index 4e06a92a5986d7bfdc698b2a61668bc7f5bbf965..22e847ba2ac4d6f5e853a4f2e511f135b1251dd3 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -712,13 +712,13 @@ extern int ubi_ioctl(struct tcb *, long, long);
 extern int loop_ioctl(struct tcb *, long, long);
 extern int ptp_ioctl(struct tcb *, long, long);
 
-extern int tv_nz(struct timeval *);
-extern int tv_cmp(struct timeval *, struct timeval *);
-extern double tv_float(struct timeval *);
-extern void tv_add(struct timeval *, struct timeval *, struct timeval *);
-extern void tv_sub(struct timeval *, struct timeval *, struct timeval *);
-extern void tv_mul(struct timeval *, struct timeval *, int);
-extern void tv_div(struct timeval *, struct timeval *, int);
+extern int tv_nz(const struct timeval *);
+extern int tv_cmp(const struct timeval *, const struct timeval *);
+extern double tv_float(const struct timeval *);
+extern void tv_add(struct timeval *, const struct timeval *, const struct timeval *);
+extern void tv_sub(struct timeval *, const struct timeval *, const struct timeval *);
+extern void tv_mul(struct timeval *, const struct timeval *, int);
+extern void tv_div(struct timeval *, const struct timeval *, int);
 
 /* Strace log generation machinery.
  *
diff --git a/util.c b/util.c
index ff18b87c27a82f304db90fe0f38e2c329698125b..33482d5f501b826784c972e7542b640d51f9420c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -79,13 +79,13 @@ string_to_uint(const char *str)
 }
 
 int
-tv_nz(struct timeval *a)
+tv_nz(const struct timeval *a)
 {
        return a->tv_sec || a->tv_usec;
 }
 
 int
-tv_cmp(struct timeval *a, struct timeval *b)
+tv_cmp(const struct timeval *a, const struct timeval *b)
 {
        if (a->tv_sec < b->tv_sec
            || (a->tv_sec == b->tv_sec && a->tv_usec < b->tv_usec))
@@ -97,13 +97,13 @@ tv_cmp(struct timeval *a, struct timeval *b)
 }
 
 double
-tv_float(struct timeval *tv)
+tv_float(const struct timeval *tv)
 {
        return tv->tv_sec + tv->tv_usec/1000000.0;
 }
 
 void
-tv_add(struct timeval *tv, struct timeval *a, struct timeval *b)
+tv_add(struct timeval *tv, const struct timeval *a, const struct timeval *b)
 {
        tv->tv_sec = a->tv_sec + b->tv_sec;
        tv->tv_usec = a->tv_usec + b->tv_usec;
@@ -114,7 +114,7 @@ tv_add(struct timeval *tv, struct timeval *a, struct timeval *b)
 }
 
 void
-tv_sub(struct timeval *tv, struct timeval *a, struct timeval *b)
+tv_sub(struct timeval *tv, const struct timeval *a, const struct timeval *b)
 {
        tv->tv_sec = a->tv_sec - b->tv_sec;
        tv->tv_usec = a->tv_usec - b->tv_usec;
@@ -125,7 +125,7 @@ tv_sub(struct timeval *tv, struct timeval *a, struct timeval *b)
 }
 
 void
-tv_div(struct timeval *tv, struct timeval *a, int n)
+tv_div(struct timeval *tv, const struct timeval *a, int n)
 {
        tv->tv_usec = (a->tv_sec % n * 1000000 + a->tv_usec + n / 2) / n;
        tv->tv_sec = a->tv_sec / n + tv->tv_usec / 1000000;
@@ -133,7 +133,7 @@ tv_div(struct timeval *tv, struct timeval *a, int n)
 }
 
 void
-tv_mul(struct timeval *tv, struct timeval *a, int n)
+tv_mul(struct timeval *tv, const struct timeval *a, int n)
 {
        tv->tv_usec = a->tv_usec * n;
        tv->tv_sec = a->tv_sec * n + tv->tv_usec / 1000000;