prog);
}
-static double tvdiff(const struct timeval *tv_lo,
- const struct timeval *tv_hi)
-{
- return ((tv_hi->tv_sec - tv_lo->tv_sec) +
- (tv_hi->tv_usec - tv_lo->tv_usec)/1.0e6);
-}
-
-#define DEFVEC(vtype, etype) \
- typedef struct { etype *v; size_t n, sz; } vtype
-#define VEC_INIT { 0, 0, 0 }
-#define VEC_FREE(vv) do { \
- free((vv)->v); (vv)->v 0; (vv)->n = (vv)->sz = 0; \
-} while (0)
-#define VEC_PUSH(p, vv) do { \
- size_t _want; \
- if ((vv)->n >= (vv)->sz) { \
- (vv)->sz = (vv)->sz ? 2*(vv)->sz : 32; \
- _want = (vv)->sz*sizeof(*(vv)->v); \
- (vv)->v = realloc((vv)->v, _want); \
- if (!(vv)->v) bail("out of memory allocating %zu bytes", _want); \
- } \
- (p) = &(vv)->v[(vv)->n++]; \
-} while (0)
-
#define MAXFILES (1 + 2*99 + 1)
struct file {
ident id;
}
}
+double tvdiff(const struct timeval *tv_lo, const struct timeval *tv_hi)
+{
+ return ((tv_hi->tv_sec - tv_lo->tv_sec) +
+ (tv_hi->tv_usec - tv_lo->tv_usec)/1.0e6);
+}
+
void carefully_write(int fd, const void *buf, size_t sz)
{
const unsigned char *p = buf;
* exit with status code 2.
*/
+/*----- Resizing vectors --------------------------------------------------*/
+
+#define DEFVEC(vtype, etype) \
+ typedef struct { etype *v; size_t n, sz; } vtype
+#define VEC_INIT { 0, 0, 0 }
+ /* Define VTYPE as a (structured) type for vectors holding elements
+ * of ETYPE.
+ *
+ * A vector V has `V.n' elements, addressed as `V.v[0]' up to
+ * `V.v[V.n - 1]'.
+ */
+
+#define VEC_FREE(vv) do { \
+ free((vv)->v); (vv)->v 0; (vv)->n = (vv)->sz = 0; \
+} while (0)
+ /* Free the vector VV. It's safe to free a vector multiple times. */
+
+#define VEC_PUSH(p, vv) do { \
+ size_t _want; \
+ if ((vv)->n >= (vv)->sz) { \
+ (vv)->sz = (vv)->sz ? 2*(vv)->sz : 32; \
+ _want = (vv)->sz*sizeof(*(vv)->v); \
+ (vv)->v = realloc((vv)->v, _want); \
+ if (!(vv)->v) bail("out of memory allocating %zu bytes", _want); \
+ } \
+ (p) = &(vv)->v[(vv)->n++]; \
+} while (0)
+ /* Add an initialized element to the end of vector VV, storing its
+ * address in P.
+ */
+
/*----- Parsing utilities -------------------------------------------------*/
#define PNF_JUNK 1u
/*----- System utilities --------------------------------------------------*/
+extern double tvdiff(const struct timeval *tv_lo,
+ const struct timeval *tv_hi);
+ /* Return the (signed) difference from TV_LO to TV_HI, as a floating-
+ * point number of seconds.
+ */
+
extern void sit(double t);
/* Do nothing for T seconds. As implied by the type, T may be
* fractional.