Patch to rename beanstalkd's dprintf to dbgprintf
[beanstalkd.git] / util.h
blob0034f1abf57768f0843e9ebf486fb83b40cd9a5f
1 /* util.h - util functions */
3 /* Copyright (C) 2007 Keith Rarick and Philotic Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef util_h
20 #define util_h
22 #include "config.h"
24 #if HAVE_STDINT_H
25 # include <stdint.h>
26 #endif /* else we get int types from config.h */
28 #include <stdlib.h>
29 #include <sys/time.h>
31 #define min(a,b) ((a)<(b)?(a):(b))
33 void v();
35 void warn(const char *fmt, ...);
36 void warnx(const char *fmt, ...);
38 extern char *progname;
40 #define twarn(fmt, args...) warn("%s:%d in %s: " fmt, \
41 __FILE__, __LINE__, __func__, ##args)
42 #define twarnx(fmt, args...) warnx("%s:%d in %s: " fmt, \
43 __FILE__, __LINE__, __func__, ##args)
45 #ifdef DEBUG
46 #define dbgprintf(fmt, args...) ((void) fprintf(stderr, fmt, ##args))
47 #else
48 #define dbgprintf(fmt, ...) ((void) 0)
49 #endif
51 typedef uint64_t usec;
52 #define USEC (1)
53 #define MSEC (1000 * USEC)
54 #define SECOND (1000 * MSEC)
56 usec now_usec(void);
57 usec usec_from_timeval(struct timeval *tv);
58 void timeval_from_usec(struct timeval *tv, usec t);
60 #endif /*util_h*/