blob: 8649c718777b69fc1ebe2539a92566f7b87bcc03 (
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
54
55
56
57
58
59
60
61
62
63
|
#if 0
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#define POSIX_FORCED
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "_stdio.h"
#ifdef POSIX_FORCED
#include "_syscall.h"
#define close(_fd) __scall1(close, _fd)
#endif
/** close a file stream **/
int fclose(FILE *stream)
{
flockfile(stream);
if (fflush(stream) == EOF) {
/* set errno */
return EOF;
}
if (stream->buf != stream->ibuf) {
if (stream->ibuf[0] == 'a') {
free(stream->buf);
}
}
if (close(stream->fd) == -1) {
/* errno is set automatically */
funlockfile(stream);
return EOF;
}
memset(stream, '\0', sizeof(*stream));
/*
RETURN_SUCCESS(0);
RETURN_FAILURE(CONSTANT(EOF));
*/
return 0;
}
/***
function closes ARGUMENT(stream) and its associated file. Any
unwritten data is flushed before closing. Any unread data is discarded. If the
buffer was automatically allocated, it is freed.
***/
/*
STDC(1)
*/
#endif
|