blob: 31eca1b75fea119ef8e17816b0b2faff6e8599f1 [file] [log] [blame]
Jack Jansen42218ce1997-01-31 16:15:11 +00001/***********************************************************
2Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
Jack Jansen426fa791995-08-07 14:02:12 +000032/*
33** mwfopenrf - Open resource fork as stdio file for CodeWarrior.
Jack Jansen426fa791995-08-07 14:02:12 +000034*/
35
Jack Jansenb852b741996-02-14 16:00:27 +000036#if defined(__MWERKS__) && !defined(USE_GUSI)
Jack Jansen426fa791995-08-07 14:02:12 +000037#include <stdio.h>
38#include <unix.h>
39#include <errno.h>
40#include "errno_unix.h"
41
42FILE *
43fopenRF(name, mode)
44 char *name;
45 char *mode;
46{
47 int fd;
Jack Jansen426fa791995-08-07 14:02:12 +000048 int modebits = -1;
Jack Jansen9c45a651995-08-14 12:21:50 +000049 int extramodebits = 0;
Jack Jansen426fa791995-08-07 14:02:12 +000050 char *modep;
51
52 for(modep=mode; *modep; modep++) {
53 switch(*modep) {
54 case 'r': modebits = O_RDONLY; break;
55 case 'w': modebits = O_WRONLY; extramodebits |= O_CREAT|O_TRUNC; break;
56 case 'a': modebits = O_RDONLY;
57 extramodebits |= O_CREAT|O_APPEND;
58 extramodebits &= ~O_TRUNC;
59 break;
60 case '+': modebits = O_RDWR;
61 extramodebits &= ~O_TRUNC;
62 break;
63 case 'b': extramodebits |= O_BINARY;
64 break;
65 default:
66 errno = EINVAL;
67 return NULL;
68 }
69 }
Jack Jansen9c45a651995-08-14 12:21:50 +000070 if ( modebits == -1 ) {
71 errno = EINVAL;
72 return NULL;
73 }
Jack Jansen426fa791995-08-07 14:02:12 +000074 fd = open(name, modebits|extramodebits|O_RSRC);
75 if ( fd < 0 )
76 return NULL;
77 return fdopen(fd, mode);
78}
79#endif /* __MWERKS__ */