Skip to content

Commit c339129

Browse files
author
streaksu
committed
Implement times and clearerr
1 parent f3f9280 commit c339129

File tree

14 files changed

+117
-3
lines changed

14 files changed

+117
-3
lines changed

PORTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ and their locations:
5555
- POSIX-compatible `tcsetattr`.
5656
- POSIX-compatible `tcflow`.
5757
- POSIX-compatible `fchmod`.
58+
- POSIX-compatible `times`.
5859
- All the desired optional functions.
5960
- A declaration of `sys_siglist` and `sys_nsig`.
6061

@@ -65,8 +66,8 @@ syscall interface, for example.
6566
- A `sys` directory under `source/ports/X-Y/sys`, which will be installed
6667
verbatim with the final instalation under `sys`, containing:
6768
- The definition of the `errnoval.h`, `fcntlval.h`, `timeval.h`, `statval.h`
68-
`signalval.h`, `termiosval.h`, and `ioctlval.h` headers, which define values
69-
taken by several functions that are by nature OS dependent.
69+
`signalval.h`, `termiosval.h`, `timesval.h` and `ioctlval.h` headers, which
70+
define values taken by several functions that are by nature OS dependent.
7071
- The `types` header, since the types and values are part of the OS ABI.
7172
- Any desired optional headers. for optional declarations or values.
7273

source/include/stdio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ size_t fwrite(const void *pointer, size_t size, size_t nitems, FILE *stream);
4646
size_t fread(void *pointer, size_t size, size_t nitems, FILE *stream);
4747
int feof(FILE *stream);
4848
int ferror(FILE *stream);
49+
void clearerr(FILE *stream);
4950
int fileno(FILE *stream);
5051
int putchar(int character);
5152
int getchar(void);

source/include/sys/times.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __SYS__TIMES_H__
2+
#define __SYS__TIMES_H__
3+
4+
#include <sys/types.h>
5+
#include <sys/timesval.h>
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
clock_t times(struct tms *t); // Defined by port.
12+
13+
#ifdef __cplusplus
14+
}
15+
#endif
16+
17+
#endif

source/libc/stdio/file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ int ferror(FILE *stream) {
280280
return stream->is_error;
281281
}
282282

283+
void clearerr(FILE *stream) {
284+
stream->is_eof = 0;
285+
stream->is_error = 1;
286+
}
287+
283288
int fileno(FILE *stream) {
284289
return stream->inner_fd;
285290
}

source/ports/i686-echidnaos/sys/fcntlval.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extern "C" {
1717
#define SEEK_END 1
1818
#define SEEK_CUR 2
1919

20-
#define F_SETFD 69 // Placeholder.
20+
#define F_SETFD 69 // Placeholder cuz echidnaOS has no fcntl.
21+
#define F_DUPFD 69 // Placeholder cuz echidnaOS has no fcntl.
2122

2223
#define F_OK 1
2324
#define R_OK 2
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __SYS__TIMESVAL_H__
2+
#define __SYS__TIMESVAL_H__
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
struct tms {
9+
clock_t tms_utime;
10+
clock_t tms_stime;
11+
clock_t tms_cutime;
12+
clock_t tms_cstime;
13+
};
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif
18+
19+
#endif

source/ports/i686-echidnaos/sys/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef int32_t pid_t;
2121
typedef int32_t off_t;
2222
typedef int32_t ssize_t;
2323
typedef int32_t clockid_t;
24+
typedef int32_t clock_t;
2425

2526
#ifdef __cplusplus
2627
}

source/ports/i686-echidnaos/sysdeps.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <assert.h>
66
#include <sys/api.h>
77
#include <sys/stat.h>
8+
#include <sys/times.h>
89
#include <time.h>
910
#include <stropts.h>
1011
#include <termios.h>
@@ -311,3 +312,10 @@ int fchmod(int fd, mode_t mode) {
311312
assert(!"This is a stub");
312313
return -1;
313314
}
315+
316+
clock_t times(struct tms *t) {
317+
// TODO: Implement when echidnaOS supports it.
318+
(void)t;
319+
assert(!"This is a stub");
320+
return (clock_t)-1;
321+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __SYS__TIMESVAL_H__
2+
#define __SYS__TIMESVAL_H__
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
struct tms {
9+
clock_t tms_utime;
10+
clock_t tms_stime;
11+
clock_t tms_cutime;
12+
clock_t tms_cstime;
13+
};
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif
18+
19+
#endif

source/ports/x86_64-linux/sys/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef int32_t pid_t;
2121
typedef int64_t off_t;
2222
typedef int64_t ssize_t;
2323
typedef int32_t clockid_t;
24+
typedef int64_t clock_t;
2425

2526
#ifdef __cplusplus
2627
}

0 commit comments

Comments
 (0)