From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/libstdio/fdopen.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 sys/src/libstdio/fdopen.c (limited to 'sys/src/libstdio/fdopen.c') diff --git a/sys/src/libstdio/fdopen.c b/sys/src/libstdio/fdopen.c new file mode 100755 index 000000000..c2b5034fe --- /dev/null +++ b/sys/src/libstdio/fdopen.c @@ -0,0 +1,37 @@ +/* + * Posix stdio -- fdopen + */ +#include "iolib.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; + qlock(&_stdiolk); + for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) + if(f->state==CLOSED) + break; + if(f==&_IO_stream[FOPEN_MAX]) { + qunlock(&_stdiolk); + return NULL; + } + f->fd=fd; + if(mode[0]=='a') + seek(f->fd, 0L, 2); + if(f->fd==-1) return NULL; + f->flags=0; + f->state=OPEN; + f->buf=0; + f->rp=0; + f->wp=0; + f->lp=0; + qunlock(&_stdiolk); + return f; +} -- cgit v1.2.3