]> git.sur5r.net Git - cc65/blob - libsrc/common/freopen.c
Allow "mode" argument to open() to be passed from 6502 code.
[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 /*****************************************************************************/
17 /*                                   Code                                    */
18 /*****************************************************************************/
19
20
21
22 FILE* __fastcall__ freopen (const char* name, const char* mode, FILE* f)
23 {
24     /* Check if the file is open, if so, close it */
25     if ((f->f_flags & _FOPEN) == 0) {
26         /* File is not open */
27         return (FILE*) _seterrno (EINVAL);      /* File not input */
28     }
29
30     /* Close the file. Don't bother setting the flag, it will get
31     ** overwritten by _fopen.
32     */
33     if (close (f->f_fd) < 0) {
34         /* An error occured, errno is already set */
35         return 0;
36     }
37
38     /* Open the file and return the descriptor */
39     return _fopen (name, mode, f);
40 }
41
42
43