blob: cddf296a7c389a4a5efa585db2741dba44bd6c69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <stdio.h>
#include "errno.h"
#include "nonstd/io.h"
#ifdef _POSIX_SOURCE
#include "fcntl.h"
#else
#define open(fname, flags, mode) (filename ? -1 : -1)
#endif
/** reopen a file stream with a new file **/
FILE * freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream)
{
flockfile(stream);
(void)mode;
int openmode = 0; /* modetoflag(mode); */
if (openmode == 0) {
#ifdef EINVAL
errno = EINVAL;
#endif
return NULL;
}
int fd = open(filename, openmode, 0);
if (fd == -1) {
/* set errno */
return NULL;
}
stream->fd = fd;
stream->nlocks = 0;
/*
RETURN_SUCCESS(ARGUMENT(stream));
RETURN_FAILURE(CONSTANT(NULL));
*/
return stream;
}
/***
changes the file associated with ARGUMENT(stream) to
ARGUMENT(filename). The meaning of ARGUMENT(mode) is the same as with
FUNCTION(fopen).
Whatever file is currently associated with ARGUMENT(stream) is closed,
ignoring any errors.
The error and end-of-file indicators are cleared.
***/
/*
STDC(1)
*/
|