From 2751c917e06147a876eb430241beee65ea73965d Mon Sep 17 00:00:00 2001 From: hpa Date: Tue, 23 Nov 2004 23:05:58 +0000 Subject: [PATCH] Add fopendev() --- com32/lib/fopen.c | 3 --- com32/lib/fopendev.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 com32/lib/fopendev.c diff --git a/com32/lib/fopen.c b/com32/lib/fopen.c index 5c84184..bf1e452 100644 --- a/com32/lib/fopen.c +++ b/com32/lib/fopen.c @@ -6,9 +6,6 @@ #include #include -/* This depends on O_RDONLY == 0, O_WRONLY == 1, O_RDWR == 2 */ - - FILE *fopen(const char *file, const char *mode) { int flags = O_RDONLY; diff --git a/com32/lib/fopendev.c b/com32/lib/fopendev.c new file mode 100644 index 0000000..2eb2a5a --- /dev/null +++ b/com32/lib/fopendev.c @@ -0,0 +1,43 @@ +/* + * fopendev.c + */ + +#include +#include +#include + +FILE *fopendev(const struct dev_info *dev, const char *mode) +{ + int flags = O_RDONLY; + int plus = 0; + int fd; + + while ( *mode ) { + switch ( *mode ) { + case 'r': + flags = O_RDONLY; + break; + case 'w': + flags = O_WRONLY|O_CREAT|O_TRUNC; + break; + case 'a': + flags = O_WRONLY|O_CREAT|O_APPEND; + break; + case '+': + plus = 1; + break; + } + mode++; + } + + if ( plus ) { + flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR; + } + + fd = opendev(file, flags); + + if ( fd < 0 ) + return NULL; + else + return fdopen(fd, mode); +} -- 2.7.4