]> git.sur5r.net Git - cc65/blob - libsrc/common/freopen.c
Fixed a typo
[cc65] / libsrc / common / freopen.c
1 /*
2  * freopen.c
3  *
4  * Ullrich von Bassewitz, 17.06.1998
5  */
6
7
8
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <errno.h>
12 #include "_file.h"
13
14
15
16 FILE* freopen (const char* name, const char* mode, FILE* f)
17 {
18     /* Check if the file is open, if so, close it */
19     if ((f->f_flags & _FOPEN) == 0) {
20         /* File is not open */
21         _errno = EINVAL;                /* File not input */
22         return 0;
23     }
24
25     /* Close the file. Don't bother setting the flag, it will get
26      * overwritten by _fopen.
27      */
28     if (close (f->f_fd) < 0) {
29         /* An error occured, _oserror is set */
30         return 0;
31     }
32
33     /* Open the file and return the descriptor */
34     return _fopen (name, mode, f);
35 }
36
37
38