1 /* $NetBSD: riscosfile.c,v 1.4 2005/12/11 12:16:05 christos Exp $ */
4 * Copyright (c) 2001 Ben Harris
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <lib/libsa/stand.h>
31 #include <riscoscalls.h>
32 #include <riscosfile.h>
40 riscos_open(const char *path
, struct open_file
*f
)
42 struct riscosfile
*rf
;
46 rf
= (struct riscosfile
*) alloc(sizeof(*rf
));
50 switch (f
->f_flags
& (F_READ
| F_WRITE
)) {
52 flags
= OSFind_Openin
;
55 flags
= OSFind_Openout
;
57 case F_READ
| F_WRITE
:
58 flags
= OSFind_Openup
;
65 error
= xosfind_open(flags
| osfind_ERROR_IF_DIR
|
66 osfind_ERROR_IF_ABSENT
, path
, NULL
, &rf
->file
);
68 dealloc(rf
, sizeof(*rf
));
69 return riscos_errno(error
);
75 #ifndef LIBSA_NO_FS_CLOSE
77 riscos_close(struct open_file
*f
)
79 struct riscosfile
*rf
;
80 struct os_error
*error
;
85 error
= xosfind_close(rf
->file
);
87 err
= riscos_errno(error
);
88 dealloc(rf
, sizeof(*rf
));
94 riscos_read(struct open_file
*f
, void *buf
, size_t size
, size_t *residp
)
96 struct riscosfile
*rf
;
102 #ifndef LIBSA_NO_TWIDDLE
105 error
= xosgbpb_read(rf
->file
, buf
, size
, &resid
);
108 return riscos_errno(error
);
112 #ifndef LIBSA_NO_FS_WRITE
114 riscos_write(struct open_file
*f
, void *buf
, size_t size
, size_t *residp
)
116 struct riscosfile
*rf
;
122 #ifndef LIBSA_NO_TWIDDLE
125 error
= xosgbpb_write(rf
->file
, buf
, size
, &resid
);
128 return riscos_errno(error
);
134 riscos_stat(struct open_file
*f
, struct stat
*sb
)
136 struct riscosfile
*rf
;
142 error
= xosargs_read_ext(rf
->file
, &extent
);
144 return riscos_errno(error
);
146 sb
->st_mode
= S_IFREG
| 0444;
150 sb
->st_size
= extent
;
154 #ifndef LIBSA_NO_FS_SEEK
156 riscos_seek(struct open_file
*f
, off_t offset
, int where
)
158 struct riscosfile
*rf
;
169 error
= xosargs_read_ptr(rf
->file
, &base
);
174 error
= xosargs_read_ext(rf
->file
, &base
);
182 offset
= base
+ offset
;
183 error
= xosargs_set_ptr(rf
->file
, offset
);
186 error
= xosargs_read_ptr(rf
->file
, &result
);
192 errno
= riscos_errno(error
);