]> git.sur5r.net Git - cc65/blob - libsrc/common/fdopen.c
65c02 optimization
[cc65] / libsrc / common / fdopen.c
1 /*
2  * fdopen.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* fdopen (int handle, const char* /*mode*/)
17 {
18     FILE* f;
19
20     /* Find a free file slot */
21     if (!(f = _fdesc ())) {
22         /* No slots */
23         _errno = EMFILE;                /* Too many files */
24         return 0;
25     }
26
27     /* Insert the handle, and return the descriptor */
28     f->f_fd    = handle;
29     f->f_flags = _FOPEN;
30
31     /* Return the file descriptor */
32     return f;
33 }
34
35
36
37