Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / sue.c
blobc831dc584063f095048dfef911f8249e266609ec
1 /* $Id: sue.c,v 1.1.1.1 2008/08/24 05:34:48 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"
36 extern int reclen;
37 long recloc;
39 static int c_sue(cilist *a, int flag);
41 int
42 s_rsue(cilist *a)
44 int n;
45 if(!init) f_init();
46 if((n=c_sue(a,READ))) return(n);
47 reading=1;
48 recpos=0;
49 if(curunit->uwrt) nowreading(curunit);
50 if(fread(&reclen,sizeof(int),1,cf)
51 != 1)
52 { if(feof(cf))
53 { curunit->uend = 1;
54 err(a->ciend, EOF, "start");
56 clearerr(cf);
57 err(a->cierr, errno, "start");
59 return(0);
62 int
63 s_wsue(cilist *a)
65 int n;
66 if(!init) f_init();
67 if((n=c_sue(a,WRITE))) return(n);
68 reading=0;
69 reclen=0;
70 if(!curunit->uwrt) nowwriting(curunit);
71 recloc=ftell(cf);
72 fseek(cf,(long)sizeof(int),1);
73 return(0);
76 int
77 c_sue(cilist *a, int flag)
79 if(a->ciunit >= MXUNIT || a->ciunit < 0)
80 err(a->cierr,101,"startio");
81 external=sequential=1;
82 formatted=0;
83 curunit = &units[a->ciunit];
84 elist=a;
85 if(curunit->ufd==NULL && fk_open(flag,SEQ,UNF,a->ciunit))
86 err(a->cierr,114,"sue");
87 cf=curunit->ufd;
88 if(curunit->ufmt) err(a->cierr,103,"sue")
89 if(!curunit->useek) err(a->cierr,103,"sue")
90 return(0);
93 int
94 e_wsue()
95 { long loc;
96 fwrite(&reclen,sizeof(int),1,cf);
97 loc=ftell(cf);
98 fseek(cf,recloc,0);
99 fwrite(&reclen,sizeof(int),1,cf);
100 fseek(cf,loc,0);
101 return(0);
105 e_rsue()
107 fseek(cf,(long)(reclen-recpos+sizeof(int)),1);
108 return(0);