1*47943Sbostic /*-
2*47943Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47943Sbostic * All rights reserved.
42484Sdlw *
5*47943Sbostic * %sccs.include.proprietary.c%
623063Skre */
723063Skre
8*47943Sbostic #ifndef lint
9*47943Sbostic static char sccsid[] = "@(#)backspace.c 5.3 (Berkeley) 04/12/91";
10*47943Sbostic #endif /* not lint */
11*47943Sbostic
1223063Skre /*
132484Sdlw * Backspace records
142484Sdlw */
152484Sdlw
162484Sdlw #include "fio.h"
172484Sdlw
1810674Sdlw static char bksp[] = "backspace";
1910674Sdlw char last_char();
202484Sdlw
f_back(a)2110674Sdlw f_back(a)
2210674Sdlw alist *a;
232484Sdlw { unit *b;
242484Sdlw int n,i;
252484Sdlw long x,y;
264728Sdlw
272484Sdlw lfname = NULL;
282484Sdlw elist = NO;
292484Sdlw external = YES;
302484Sdlw errflag = a->aerr;
312484Sdlw lunit = a->aunit;
3210674Sdlw if (not_legal(lunit))
3310674Sdlw err(errflag, F_ERUNIT, bksp)
342484Sdlw b= &units[lunit];
3524094Sjerry if(!b->ufd) return(OK);
362484Sdlw lfname = b->ufnm;
372484Sdlw if(b->uend)
382484Sdlw { b->uend = NO;
396600Sdlw clearerr(b->ufd);
402484Sdlw return(OK);
412484Sdlw }
4210674Sdlw if((x = ftell(b->ufd)) == 0)
4310674Sdlw return(OK);
4410674Sdlw if(!b->useek)
4510674Sdlw err(errflag, F_ERNOBKSP, bksp)
4614824Sdlw if(b->uwrt && (n = t_runc(b, errflag, bksp))) /* sets 'reading' */
4710674Sdlw return(n);
482484Sdlw if(b->url) /* direct access, purely academic */
492484Sdlw { y = x%(long)b->url;
502484Sdlw x -= y?y:b->url;
512484Sdlw fseek(b->ufd,x,0);
522484Sdlw return(OK);
532484Sdlw }
542484Sdlw if(!b->ufmt) /* unformatted sequential */
552484Sdlw { fseek(b->ufd,-(long)sizeof(int),1);
562484Sdlw fread((char *)&n,sizeof(int),1,b->ufd);
572484Sdlw fseek(b->ufd,-(long)n-2*sizeof(int),1);
582484Sdlw return(OK);
592484Sdlw }
6010674Sdlw if(x == 1) /* formatted sequential */
612484Sdlw { rewind(b->ufd);
622484Sdlw return(OK);
632484Sdlw }
6410674Sdlw while (last_char(b->ufd) != '\n') /* slow but simple */
6510674Sdlw ;
662484Sdlw return(OK);
672484Sdlw }
68