Split libmaxsi time.cpp into multiple files.
This commit is contained in:
parent
0e7518915e
commit
8290f8979c
11 changed files with 316 additions and 88 deletions
|
@ -37,6 +37,7 @@ bsearch.o \
|
|||
calloc.o \
|
||||
clearerr.o \
|
||||
c++.o \
|
||||
ctime.o \
|
||||
ctype.o \
|
||||
dir.o \
|
||||
errno.o \
|
||||
|
@ -72,8 +73,12 @@ fwrite.o \
|
|||
fwriting.o \
|
||||
getdelim.o \
|
||||
getline.o \
|
||||
gmtime.o \
|
||||
gmtime_r.o \
|
||||
heap.o \
|
||||
integer.o \
|
||||
localtime.o \
|
||||
localtime_r.o \
|
||||
mbtowc.o \
|
||||
memchr.o \
|
||||
memcmp.o \
|
||||
|
@ -117,6 +122,7 @@ HOSTEDOBJS=\
|
|||
access.o \
|
||||
chdir.o \
|
||||
chmod.o \
|
||||
clock.o \
|
||||
close.o \
|
||||
$(CPUDIR)/fork.o \
|
||||
$(CPUDIR)/signal.o \
|
||||
|
@ -151,6 +157,7 @@ getpagesize.o \
|
|||
getpid.o \
|
||||
getppid.o \
|
||||
gettermmode.o \
|
||||
gettimeofday.o \
|
||||
init.o \
|
||||
ioleast.o \
|
||||
isatty.o \
|
||||
|
@ -184,7 +191,9 @@ time.o \
|
|||
truncate.o \
|
||||
umask.o \
|
||||
unlink.o \
|
||||
uptime.o \
|
||||
usleep.o \
|
||||
utime.o \
|
||||
vexecle.o \
|
||||
vexecl.o \
|
||||
vexeclp.o \
|
||||
|
|
32
libmaxsi/clock.cpp
Normal file
32
libmaxsi/clock.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
clock.cpp
|
||||
Determine processor time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
extern "C" clock_t clock(void)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
30
libmaxsi/ctime.cpp
Normal file
30
libmaxsi/ctime.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
ctime.cpp
|
||||
Transform date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern "C" char* ctime(const time_t* /*timep*/)
|
||||
{
|
||||
return (char*) "ctime(3) is not implemented";
|
||||
}
|
36
libmaxsi/gettimeofday.cpp
Normal file
36
libmaxsi/gettimeofday.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
gettimeofday.cpp
|
||||
Get date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" int gettimeofday(struct timeval* tp, void* /*tzp*/)
|
||||
{
|
||||
uintmax_t sinceboot;
|
||||
uptime(&sinceboot);
|
||||
tp->tv_sec = sinceboot / 1000000ULL;
|
||||
tp->tv_usec = sinceboot % 1000000ULL;
|
||||
return 0;
|
||||
}
|
31
libmaxsi/gmtime.cpp
Normal file
31
libmaxsi/gmtime.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
gmtime.cpp
|
||||
Transform date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern "C" struct tm* gmtime(const time_t* timer)
|
||||
{
|
||||
static struct tm hack_gmtime_ret;
|
||||
return gmtime_r(timer, &hack_gmtime_ret);
|
||||
}
|
30
libmaxsi/gmtime_r.cpp
Normal file
30
libmaxsi/gmtime_r.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
gmtime_r.cpp
|
||||
Transform date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern "C" struct tm* gmtime_r(const time_t* timer, struct tm* ret)
|
||||
{
|
||||
return localtime_r(timer, ret);
|
||||
}
|
31
libmaxsi/localtime.cpp
Normal file
31
libmaxsi/localtime.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
localtime.cpp
|
||||
Transform date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern "C" struct tm* localtime(const time_t* timer)
|
||||
{
|
||||
static struct tm hack_localtime_ret;
|
||||
return localtime_r(timer, &hack_localtime_ret);
|
||||
}
|
39
libmaxsi/localtime_r.cpp
Normal file
39
libmaxsi/localtime_r.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
localtime_r.cpp
|
||||
Transform date and time.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern "C" struct tm* localtime_r(const time_t* timer, struct tm* ret)
|
||||
{
|
||||
time_t time = *timer;
|
||||
ret->tm_sec = time % 60; // No leap seconds.
|
||||
ret->tm_min = (time / 60) % 60;
|
||||
ret->tm_hour = (time / 60 / 60) % 24;
|
||||
ret->tm_mday = 0;
|
||||
ret->tm_mon = 0;
|
||||
ret->tm_year = 0;
|
||||
ret->tm_wday = 0;
|
||||
ret->tm_isdst = 0;
|
||||
return ret;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
|
@ -11,102 +11,25 @@
|
|||
|
||||
LibMaxsi 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 Lesser General Public License for
|
||||
more details.
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
time.cpp
|
||||
Useful time functions.
|
||||
Get time in seconds.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
namespace Maxsi
|
||||
extern "C" time_t time(time_t* t)
|
||||
{
|
||||
namespace Time
|
||||
{
|
||||
DEFN_SYSCALL1(int, SysUptime, SYSCALL_UPTIME, uintmax_t*);
|
||||
|
||||
extern "C" int uptime(uintmax_t* usecssinceboot)
|
||||
{
|
||||
return SysUptime(usecssinceboot);
|
||||
}
|
||||
|
||||
extern "C" clock_t clock(void)
|
||||
{
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
extern "C" int gettimeofday(struct timeval* tp, void* /*tzp*/)
|
||||
{
|
||||
uintmax_t sinceboot;
|
||||
uptime(&sinceboot);
|
||||
tp->tv_sec = sinceboot / 1000000ULL;
|
||||
tp->tv_usec = sinceboot % 1000000ULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" time_t time(time_t* t)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
time_t result = tv.tv_sec;
|
||||
return t ? *t = result : result;
|
||||
}
|
||||
|
||||
extern "C" struct tm* localtime_r(const time_t* timer, struct tm* ret)
|
||||
{
|
||||
time_t time = *timer;
|
||||
ret->tm_sec = time % 60; // No leap seconds.
|
||||
ret->tm_min = (time / 60) % 60;
|
||||
ret->tm_hour = (time / 60 / 60) % 24;
|
||||
ret->tm_mday = 0;
|
||||
ret->tm_mon = 0;
|
||||
ret->tm_year = 0;
|
||||
ret->tm_wday = 0;
|
||||
ret->tm_isdst = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" struct tm* gmtime_r(const time_t* timer, struct tm* ret)
|
||||
{
|
||||
return localtime_r(timer, ret);
|
||||
}
|
||||
|
||||
// TODO: Who the hell designed the below two functions? I vote that
|
||||
// these be removed from Sortix soon - although that'd require fixing
|
||||
// a lot of applications..
|
||||
|
||||
extern "C" struct tm* localtime(const time_t* timer)
|
||||
{
|
||||
static struct tm hack_localtime_ret;
|
||||
return localtime_r(timer, &hack_localtime_ret);
|
||||
}
|
||||
|
||||
extern "C" struct tm* gmtime(const time_t* timer)
|
||||
{
|
||||
static struct tm hack_gmtime_ret;
|
||||
return gmtime_r(timer, &hack_gmtime_ret);
|
||||
}
|
||||
|
||||
extern "C" char* ctime(const time_t* /*timep*/)
|
||||
{
|
||||
return (char*) "ctime(3) is not implemented";
|
||||
}
|
||||
|
||||
extern "C" int utime(const char* filepath, const struct utimbuf* times)
|
||||
{
|
||||
// TODO: Sure, I did that! There is no kernel support for this yet.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
time_t result = tv.tv_sec;
|
||||
return t ? *t = result : result;
|
||||
}
|
||||
|
|
34
libmaxsi/uptime.cpp
Normal file
34
libmaxsi/uptime.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
uptime.cpp
|
||||
Returns current system uptime.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DEFN_SYSCALL1(int, sys_uptime, SYSCALL_UPTIME, uintmax_t*);
|
||||
|
||||
extern "C" int uptime(uintmax_t* usecssinceboot)
|
||||
{
|
||||
return sys_uptime(usecssinceboot);
|
||||
}
|
33
libmaxsi/utime.cpp
Normal file
33
libmaxsi/utime.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of LibMaxsi.
|
||||
|
||||
LibMaxsi is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
LibMaxsi 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 Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
utime.cpp
|
||||
Change file last access and modification times.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
//#include <utime.h>
|
||||
#include <time.h>
|
||||
|
||||
extern "C" int utime(const char* filepath, const struct utimbuf* times)
|
||||
{
|
||||
// TODO: Sure, I did that! There is no kernel support for this yet.
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue