2007-06-11 13:01:04 +01:00
|
|
|
/*
|
|
|
|
* Scyther : An automatic verifier for security protocols.
|
|
|
|
* Copyright (C) 2007 Cas Cremers
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2005-01-05 15:29:27 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
2006-08-02 10:32:29 +01:00
|
|
|
/*
|
|
|
|
* Timer functions
|
|
|
|
*
|
|
|
|
* Currently, this only works under linux (where the linux macro is defined by the compiler). Otherwise, it simply assumes the timer is never passed.
|
|
|
|
*/
|
|
|
|
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
#include <time.h>
|
2010-11-10 22:13:29 +00:00
|
|
|
#include <unistd.h>
|
2005-01-05 15:29:27 +00:00
|
|
|
#include <sys/times.h>
|
2006-08-02 10:27:09 +01:00
|
|
|
static clock_t endwait = 0;
|
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
|
|
|
|
static int time_max_seconds = 0;
|
|
|
|
|
|
|
|
//! Set initial time limit.
|
|
|
|
/**
|
|
|
|
* <= 0 means none.
|
|
|
|
*/
|
2005-06-02 10:40:05 +01:00
|
|
|
void
|
|
|
|
set_time_limit (int seconds)
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
|
|
|
time_max_seconds = seconds;
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2010-11-10 22:13:29 +00:00
|
|
|
endwait = seconds * sysconf (_SC_CLK_TCK);
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time_max_seconds = 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
endwait = 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Retrieve time limit
|
2005-06-02 10:40:05 +01:00
|
|
|
int
|
|
|
|
get_time_limit ()
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
|
|
|
return time_max_seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Check whether time limit has passed.
|
2005-06-02 10:40:05 +01:00
|
|
|
int
|
|
|
|
passed_time_limit ()
|
2005-01-05 15:29:27 +00:00
|
|
|
{
|
2006-08-02 10:27:09 +01:00
|
|
|
#ifdef linux
|
2005-01-05 15:29:27 +00:00
|
|
|
if (endwait <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct tms t;
|
|
|
|
|
2005-06-02 10:40:05 +01:00
|
|
|
times (&t);
|
2010-11-10 22:13:29 +00:00
|
|
|
if ((t.tms_utime + t.tms_stime) > endwait)
|
2005-06-02 10:40:05 +01:00
|
|
|
return 1;
|
2005-01-05 15:29:27 +00:00
|
|
|
else
|
2005-06-02 10:40:05 +01:00
|
|
|
return 0;
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|
2006-08-02 10:27:09 +01:00
|
|
|
#else
|
2006-08-02 10:32:29 +01:00
|
|
|
return 0;
|
2006-08-02 10:27:09 +01:00
|
|
|
#endif
|
2005-01-05 15:29:27 +00:00
|
|
|
}
|