- sicsutil.c contains code from acces.c and the function DoubleTime
This commit is contained in:
53
sicsutil.c
Normal file
53
sicsutil.c
Normal file
@ -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 <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
17
sicsutil.h
Normal file
17
sicsutil.h
Normal file
@ -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 */
|
||||
|
||||
|
Reference in New Issue
Block a user