diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/msntab.c | 23 | ||||
-rw-r--r-- | src/msntab.h | 17 | ||||
-rw-r--r-- | src/timevalarith.c | 53 | ||||
-rw-r--r-- | src/timevalarith.h | 11 |
4 files changed, 104 insertions, 0 deletions
diff --git a/src/msntab.c b/src/msntab.c new file mode 100644 index 0000000..bcd3030 --- /dev/null +++ b/src/msntab.c @@ -0,0 +1,23 @@ +#include <stddef.h> +#include <assert.h> +#include "msntab.h" + +struct tabentry* msntab_check_call(const char *callee, const char *caller) { + static char *args[] = { "/bin/cat", NULL }; + static struct tabentry ca = { CALL_ACTION_ACCEPT, 1, args }; + + return msntab_ref(&ca); +} + + +struct tabentry* msntab_ref(struct tabentry *t) { + assert(t && t->ref_counter >= 1); + t->ref_counter++; + return t; +} + +void msntab_unref(struct tabentry *t) { + assert(t && t->ref_counter >= 1); + t->ref_counter--; +} + diff --git a/src/msntab.h b/src/msntab.h new file mode 100644 index 0000000..28de484 --- /dev/null +++ b/src/msntab.h @@ -0,0 +1,17 @@ +#ifndef foomsntabhfoo +#define foomsntabhfoo + +enum call_action { CALL_ACTION_IGNORE, CALL_ACTION_ACCEPT, CALL_ACTION_HANGUP }; + +struct tabentry { + enum call_action action; + int ref_counter; + + char **args; +}; + +struct tabentry* msntab_check_call(const char *callee, const char *caller); +struct tabentry* msntab_ref(struct tabentry *t); +void msntab_unref(struct tabentry *t); + +#endif diff --git a/src/timevalarith.c b/src/timevalarith.c new file mode 100644 index 0000000..1091192 --- /dev/null +++ b/src/timevalarith.c @@ -0,0 +1,53 @@ +#include "timevalarith.h" + +struct timeval timeval_max(struct timeval a, struct timeval b) { + + if (a.tv_sec > b.tv_sec) + return a; + + if (a.tv_sec < b.tv_sec) + return b; + + if (a.tv_usec > b.tv_usec) + return a; + + return b; +} + +struct timeval timeval_add(struct timeval a, uint32_t d) { + uint64_t sec, usec; + struct timeval r; + + sec = (uint64_t) a.tv_sec + (d / 1000000L); + usec = (uint64_t) a.tv_usec + (d % 1000000L); + + while (usec > 1000000L) { + usec -= 1000000L; + sec++; + } + + r.tv_sec = (long) sec; + r.tv_usec = (long) usec; + return r; +} + +struct timeval timeval_sub(struct timeval a, uint32_t d) { + uint64_t sec, usec; + struct timeval r; + + sec = (uint64_t) a.tv_sec - (d / 1000000L); + usec = (uint64_t) a.tv_usec; + + d = (d % 1000000L); + + if (usec > d) + usec -= d; + else { + sec--; + usec = 1000000L + usec - d; + } + + r.tv_sec = (long) sec; + r.tv_usec = (long) usec; + return r; +} diff --git a/src/timevalarith.h b/src/timevalarith.h new file mode 100644 index 0000000..c0c015b --- /dev/null +++ b/src/timevalarith.h @@ -0,0 +1,11 @@ +#ifndef footimevalarithhfoo +#define footimevalarithhfoo + +#include <sys/types.h> +#include <inttypes.h> + +struct timeval timeval_max(struct timeval a, struct timeval b); +struct timeval timeval_add(struct timeval a, uint32_t d); +struct timeval timeval_sub(struct timeval a, uint32_t s); + +#endif |