Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / backspace.c
blob2e9b55fd27b2cc63a6cf6f26832ccee04a369c64
1 /* $Id: backspace.c,v 1.1.1.1 2008/08/24 05:34:47 gmcgarry Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 #include "fio.h"
37 int
38 f_back(alist *a)
40 unit *b;
41 int n,i;
42 long x;
43 char buf[32];
45 if(a->aunit >= MXUNIT || a->aunit < 0)
46 err(a->aerr,101,"backspace")
47 b= &units[a->aunit];
48 if(b->useek==0) err(a->aerr,106,"backspace")
49 if(b->ufd==NULL) err(a->aerr,114,"backspace")
50 if(b->uend==1)
51 { b->uend=0;
52 return(0);
54 if(b->uwrt)
55 { t_runc(b);
56 nowreading(b);
58 if(b->url>0)
60 x=ftell(b->ufd);
61 x /= b->url;
62 x *= b->url;
63 fseek(b->ufd,x,0);
64 return(0);
66 if(b->ufmt==0)
67 { fseek(b->ufd,-(long)sizeof(int),1);
68 fread((char *)&n,sizeof(int),1,b->ufd);
69 fseek(b->ufd,-(long)n-2*sizeof(int),1);
70 return(0);
72 for(;;)
74 x=ftell(b->ufd);
75 if(x<sizeof(buf)) x=0;
76 else x -= sizeof(buf);
77 fseek(b->ufd,x,0);
78 n=fread(buf,1,sizeof(buf),b->ufd);
79 for(i=n-1;i>=0;i--)
81 if(buf[i]!='\n') continue;
82 fseek(b->ufd,(long)(i-n),1);
83 return(0);
85 if(x==0) return(0);
86 else if(n==0) err(a->aerr,(EOF),"backspace")
87 else err(a->aerr,errno,"backspace");