source: buchla-68k/libcio/readrn.c@ 6099cac

Last change on this file since 6099cac was 8973acd, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in libcio.

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 readrn.c -- read a random sector from a file
4 Version 8 -- 1987-12-15 -- D.N. Lynx Crowe
5
6 int
7 ReadRN(fcp, buf)
8 struct fcb *fcp;
9 char *buf;
10
11 Reads a sector from file 'fcp' into 'buf'. Seeks as needed.
12 Returns 0 if OK, -1 for errors, 1 for EOF (no data returned).
13 =============================================================================
14*/
15
16#define DEBUGIT 0
17
[b28a12e]18#include "ram.h"
[f40a309]19
20/*
21 =============================================================================
22 ReadRN(fcp, buf) -- Reads a sector from file 'fcp' into 'buf'.
23 Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
24 =============================================================================
25*/
26
[7258c6a]27int16_t ReadRN(struct fcb *fcp, int8_t *buf)
[f40a309]28{
[7258c6a]29 int16_t sv; /* seek return code */
30 int32_t brc; /* bios return code */
[f40a309]31
[8973acd]32 if ((sv = _seek(fcp))) { /* try to find the sector we want */
[f40a309]33 if (sv < 0) {
34
35 errno = EIO; /* I/O error */
36 return(-1); /* return: ERROR */
37
38 } else {
39
40 errno = EINVAL; /* invalid argument */
41 return(1); /* return: EOF */
42 }
[8973acd]43 }
[f40a309]44
45#if DEBUGIT
46 if (fsdebug)
47 printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
48 fcp->curlsn, fcp->curdsn, fcp->offset);
49#endif
50
51#if TBUFFER
[8973acd]52 if ((brc = _secrd(buf, (int16_t)fcp->curdsn))) {
[f40a309]53#else
54 if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
55#endif
56
57 _berrno = brc; /* log the error */
58 errno = EIO; /* ... as an I/O error */
59 return(FAILURE); /* return: ERROR */
60 }
61
62 return(SUCCESS); /* return: SUCCESS */
63}
[6262b5c]64
Note: See TracBrowser for help on using the repository browser.