BSD 4 development
[unix-history] / .ref-5cb41021d721f4e0ac572d592613f963e495d1ff / usr / src / old / sdb / old.c
CommitLineData
f52e2df2
BJ
1static char sccsid[] = "@(#)old.c 4.1 %G%";
2/*
3 * sdb - a symbolic debugger for UNIX.
4 */
5
6/*
7 * This file contains support routines for older versions of the system.
8 */
9
10#ifndef VMUNIX
11/*
12 * These routines are used only if the system
13 * doesn't have virtual memory. They
14 * are used only to read the symbol table, which
15 * is simply kept in VM on VMUNIX.
16 */
17#include <pagsiz.h>
18#include "bio.h"
19
20bread(brs, buff, nbytes)
21struct brbuf *brs; char *buff; {
22 register int k, nb;
23
24 if (nbytes > 0) {
25 for (nb=nbytes; nb>0; nb--) {
26 if (brs->nr == 0) {
27 brs->nr = read(brs->fd, brs->next=brs->b, BSIZE);
28 brs->nl = 0;
29 if (brs->nr < 0) return(-1);
30 if (brs->nr == 0) return(nbytes-nb);
31 }
32 *buff++ = *brs->next++;
33 brs->nr--;
34 brs->nl++;
35 }
36 }
37 else {
38 nbytes = -nbytes;
39 for (nb=nbytes; nb>0; nb--) {
40 if (brs->nl == 0) {
41 if ((k=tell(brs->fd)) >= BSIZE + brs->nr) {
42 lseek(brs->fd, (long) -(BSIZE + brs->nr), 1);
43 brs->nl = read(brs->fd, brs->b, BSIZE);
44 } else {
45 lseek(brs->fd, 0L, 0);
46 k = k - brs->nr;
47 if (k < 0) k = 0;
48 brs->nl = read(brs->fd, brs->b, k);
49 }
50 if (brs->nl == 0) return(nbytes-nb);
51 brs->next = brs->b + brs->nl;
52 brs->nr = 0;
53 }
54 *--buff = *--brs->next;
55 brs->nr++;
56 brs->nl--;
57 }
58 }
59 return(nbytes);
60 }
61
62blseek(brs, offset, flag)
63struct brbuf *brs; long offset; {
64 brs->nl = 0;
65 brs->nr = 0;
66 return(lseek(brs->fd,offset,flag));
67 }
68
69binit(brs)
70struct brbuf *brs; {
71 brs->nl = brs->nr = 0;
72}
73
74long
75tell(fildes) {
76 return(lseek(fildes, 0L, 1));
77}
78#endif