2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Jelmer Vernooij 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 return the number of elements in a string list
27 static size_t str_list_length(const char **list
)
30 for (ret
=0;list
&& list
[ret
];ret
++) /* noop */ ;
35 add an entry to a string list
37 const char **str_list_add(const char **list
, const char *s
)
39 size_t len
= str_list_length(list
);
42 ret
= talloc_realloc(NULL
, list
, const char *, len
+2);
43 if (ret
== NULL
) return NULL
;
45 ret
[len
] = talloc_strdup(ret
, s
);
46 if (ret
[len
] == NULL
) return NULL
;
54 compare two timeval structures.
55 Return -1 if tv1 < tv2
56 Return 0 if tv1 == tv2
59 static int timeval_compare(const struct timeval
*tv1
, const struct timeval
*tv2
)
61 if (tv1
->tv_sec
> tv2
->tv_sec
) return 1;
62 if (tv1
->tv_sec
< tv2
->tv_sec
) return -1;
63 if (tv1
->tv_usec
> tv2
->tv_usec
) return 1;
64 if (tv1
->tv_usec
< tv2
->tv_usec
) return -1;
71 struct timeval
timeval_zero(void)
80 return true if a timeval is zero
82 bool timeval_is_zero(const struct timeval
*tv
)
84 return tv
->tv_sec
== 0 && tv
->tv_usec
== 0;
88 return a timeval for the current time
90 struct timeval
timeval_current(void)
98 return a timeval struct with the given elements
100 struct timeval
timeval_set(uint32_t secs
, uint32_t usecs
)
109 return the difference between two timevals as a timeval
110 if tv1 comes after tv2, then return a zero timeval
111 (this is *tv2 - *tv1)
113 struct timeval
timeval_until(const struct timeval
*tv1
,
114 const struct timeval
*tv2
)
117 if (timeval_compare(tv1
, tv2
) >= 0) {
118 return timeval_zero();
120 t
.tv_sec
= tv2
->tv_sec
- tv1
->tv_sec
;
121 if (tv1
->tv_usec
> tv2
->tv_usec
) {
123 t
.tv_usec
= 1000000 - (tv1
->tv_usec
- tv2
->tv_usec
);
125 t
.tv_usec
= tv2
->tv_usec
- tv1
->tv_usec
;