summaryrefslogtreecommitdiffstats
path: root/ffd/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'ffd/util.h')
-rw-r--r--ffd/util.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/ffd/util.h b/ffd/util.h
new file mode 100644
index 0000000..8020381
--- /dev/null
+++ b/ffd/util.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (c) 2012, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef _FFD_UTIL_H_
+#define _FFD_UTIL_H_
+
+#include "types.h"
+
+#include <stdarg.h>
+#include <time.h>
+
+
+bool file_readv(const char *file, const char *format, va_list ap);
+
+
+static inline bool are_eth_addrs_equal(const eth_addr_t *address1, const eth_addr_t *address2) {
+ const uint8_t *a = address1->d;
+ const uint8_t *b = address2->d;
+
+ return (a[0]==b[0] && a[1]==b[1] && a[2]==b[2] && a[3]==b[3] && a[4]==b[4] && a[5]==b[5]);
+}
+
+/* returns (tp1 - tp2) in milliseconds */
+static inline int timespec_diff(const struct timespec *tp1, const struct timespec *tp2) {
+ return ((tp1->tv_sec - tp2->tv_sec))*1000 + (tp1->tv_nsec - tp2->tv_nsec)/1e6;
+}
+
+#endif /* _FFD_UTIL_H_ */