Compare commits

..

2 Commits

Author SHA1 Message Date
1db60b5a82
sh: Print a message on exit
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-20 12:07:56 +02:00
a7c6163e7c
libc: Add gettimeofday() 2023-05-20 12:05:22 +02:00
5 changed files with 53 additions and 2 deletions

View File

@ -86,7 +86,11 @@ Result<int> luna_main(int argc, char** argv)
}
auto cmd = TRY(input_file->read_line());
if (cmd.is_empty()) break;
if (cmd.is_empty())
{
puts("exit");
break;
}
if (strspn(cmd.chars(), " \n") == cmd.length()) continue;

View File

@ -1,4 +1,4 @@
/* bits/timespec.h: The timespec structure. */
/* bits/timespec.h: The timespec and timeval structures. */
#ifndef _BITS_TIMESPEC_H
#define _BITS_TIMESPEC_H
@ -11,4 +11,10 @@ struct timespec
long tv_nsec;
};
struct timeval
{
time_t tv_sec;
suseconds_t tv_usec;
};
#endif

21
libc/include/sys/time.h Normal file
View File

@ -0,0 +1,21 @@
/* sys/time.h: POSIX time types. */
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <bits/attrs.h>
#include <bits/timespec.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Get the current time of day. */
__deprecated int gettimeofday(struct timeval* tp, void* timezone);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,6 +19,7 @@ typedef __u64_t ino_t;
typedef __u32_t uid_t;
typedef __u32_t gid_t;
typedef __u64_t nlink_t;
typedef __i64_t suseconds_t;
typedef off_t fpos_t;

View File

@ -1,6 +1,8 @@
#include <bits/errno-return.h>
#include <luna/Check.h>
#include <luna/Format.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
@ -148,4 +150,21 @@ extern "C"
{
return asctime(localtime(tp));
}
int gettimeofday(struct timeval* tp, void* timezone)
{
if (timezone)
{
fputs("gettimeofday: timezone was not NULL, abort\n", stderr);
abort();
}
struct timespec ts;
if (clock_gettime(CLOCK_REALTIME, &ts) < 0) return -1;
tp->tv_sec = ts.tv_sec;
tp->tv_usec = ts.tv_nsec / 1000;
return 0;
}
}