source: buchla-68k/orig/IOLIB/READRN.C@ d21fc6f

Last change on this file since d21fc6f was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[3ae31e9]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
18#include "stddefs.h"
19#include "biosdefs.h"
20#include "errno.h"
21#include "errdefs.h"
22#include "fspars.h"
23
24#if DEBUGIT
25extern short fsdebug;
26#endif
27
28#if TBUFFER
29extern long _secrd();
30#endif
31
32extern long _berrno;
33extern int _seek();
34
35/*
36
37*/
38
39/*
40 =============================================================================
41 ReadRN(fcp, buf) -- Reads a sector from file 'fcp' into 'buf'.
42 Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
43 =============================================================================
44*/
45
46int
47ReadRN(fcp, buf)
48struct fcb *fcp;
49char *buf;
50{
51 int sv; /* seek return code */
52 long brc; /* bios return code */
53
54 if (sv = _seek(fcp)) /* try to find the sector we want */
55 if (sv < 0) {
56
57 errno = EIO; /* I/O error */
58 return(-1); /* return: ERROR */
59
60 } else {
61
62 errno = EINVAL; /* invalid argument */
63 return(1); /* return: EOF */
64 }
65
66#if DEBUGIT
67 if (fsdebug)
68 printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
69 fcp->curlsn, fcp->curdsn, fcp->offset);
70#endif
71
72#if TBUFFER
73 if (brc = _secrd(buf, (short)fcp->curdsn)) {
74#else
75 if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
76#endif
77
78 _berrno = brc; /* log the error */
79 errno = EIO; /* ... as an I/O error */
80 return(FAILURE); /* return: ERROR */
81 }
82
83 return(SUCCESS); /* return: SUCCESS */
84}
Note: See TracBrowser for help on using the repository browser.