blob: b3061fbe753f48f5cd5fa2d117cc7724ed7a3109 (
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
|
/*
* Posix stdio -- fdopen
*/
#include "iolib.h"
#include <errno.h>
/*
* Open the named file with the given mode, using the given FILE
* Legal modes are given below, `additional characters may follow these sequences':
* r rb open to read
* w wb open to write, truncating
* a ab open to write positioned at eof, creating if non-existant
* r+ r+b rb+ open to read and write, creating if non-existant
* w+ w+b wb+ open to read and write, truncating
* a+ a+b ab+ open to read and write, positioned at eof, creating if non-existant.
*/
FILE *fdopen(const int fd, const char *mode){
FILE *f;
if(fd < 0){
errno = EBADF;
return NULL;
}
if((f = _IO_newfile()) == NULL)
return NULL;
f->fd=fd;
if(mode[0]=='a')
lseek(f->fd, 0L, 2);
f->flags=0;
f->state=OPEN;
f->buf=0;
f->rp=0;
f->wp=0;
f->lp=0;
return f;
}
|