diff --git a/sicsutil.c b/sicsutil.c new file mode 100644 index 00000000..89abbe5c --- /dev/null +++ b/sicsutil.c @@ -0,0 +1,53 @@ +/** + * Some general functions for SICS. Most part is moved from ofac.c + * + * copyright: see file COPYRIGHT + * + * moved from acces.c and ascon.c Markus Zolliker Jan 2010 + */ +#include +#include +#include +#include +#include "fortify.h" +#include "sics.h" + +static char *aCode[] = { + "internal", + "mugger", + "user", + "spy", + NULL +}; +static int iCodes = 4; +/*--------------------------------------------------------------------------*/ +int decodeSICSPriv(char *privText) +{ + int code = 0; + + strtolower(privText); + while (aCode[code] != NULL) { + if (strcmp(aCode[code], privText) == 0) { + return code; + } + code++; + } + if (code >= iCodes) { + return -1; + } + return -1; +} + + +/*-------------------------------------------------------------------------*/ +double DoubleTime(void) +{ + struct timeval now; + /* the resolution of this function is usec, if the machine supports this + and the mantissa of a double is 51 bits or more (31 for sec and 20 for mic$ + */ + gettimeofday(&now, NULL); + return now.tv_sec + now.tv_usec / 1e6; +} + + diff --git a/sicsutil.h b/sicsutil.h new file mode 100644 index 00000000..191c0d7d --- /dev/null +++ b/sicsutil.h @@ -0,0 +1,17 @@ +/** + * Some general functions for SICS. + * + * copyright: see file COPYRIGHT + * + * + * Decode privilege text. moved from access.c by M. Zolliker Jan 2010 + * @param the text to decode + * @return -1 if code invalid, else the privilege code + */ +int decodeSICSPriv(char *privText); + +double DoubleTime(void); +/* returns time since epoch in seconds + the resultion is machine dependent, but mostly better than msec */ + +