mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
Add gettimeofday() syscall and LibC wrappers gettimeofday() and time().
This only has second accuracy right now, I'll work out subseconds later.
This commit is contained in:
parent
5978185242
commit
dc6f57f19c
20 changed files with 188 additions and 8 deletions
|
@ -6,6 +6,7 @@ OBJS = \
|
|||
mman.o \
|
||||
dirent.o \
|
||||
stdlib.o \
|
||||
time.o \
|
||||
entry.o
|
||||
|
||||
LIBRARY = LibC.a
|
||||
|
|
21
LibC/time.cpp
Normal file
21
LibC/time.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "time.h"
|
||||
#include "errno.h"
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
time_t time(time_t* tloc)
|
||||
{
|
||||
timeval tv;
|
||||
if (gettimeofday(&tv) < 0)
|
||||
return (time_t)-1;
|
||||
return tv.tv_sec;
|
||||
}
|
||||
|
||||
int gettimeofday(timeval* tv)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::PosixGettimeofday, (dword)tv);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
}
|
11
LibC/time.h
Normal file
11
LibC/time.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
int gettimeofday(timeval*);
|
||||
time_t time(time_t*);
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,12 @@ typedef dword nlink_t;
|
|||
typedef dword blksize_t;
|
||||
typedef dword blkcnt_t;
|
||||
typedef dword time_t;
|
||||
typedef dword suseconds_t;
|
||||
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
suseconds_t tv_usec;
|
||||
};
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev; /* ID of device containing file */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue