1 /* $XConsortium: sfsize.c /main/3 1995/11/01 18:36:22 rswiston $ */
2 /***************************************************************
6 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
9 * Copyright (c) 1995 AT&T Corp. *
10 * All Rights Reserved *
12 * This software is licensed by AT&T Corp. *
13 * under the terms and conditions of the license in *
14 * http://www.research.att.com/orgs/ssr/book/reuse *
16 * This software was created by the *
17 * Software Engineering Research Department *
18 * AT&T Bell Laboratories *
20 * For further information contact *
21 * gsf@research.att.com *
23 ***************************************************************/
26 /* Get the size of a stream.
28 ** Written by Kiem-Phong Vo (02/12/91)
31 long sfsize(reg Sfio_t *f)
39 if((mode = f->mode&SF_RDWR) != f->mode && _sfmode(f,mode,0) < 0)
42 if(f->flags&SF_STRING)
47 if(f->extent >= 0 && (f->flags&(SF_SHARE|SF_APPEND)) )
49 for(disc = f->disc; disc; disc = disc->disc)
53 { f->extent = SFSK(f,0L,2,disc);
54 (void)SFSK(f,f->here,0,disc);
58 if(fstat(f->file,&st) < 0)
60 else f->extent = st.st_size;
66 else if(f->mode&SF_READ)
68 else if(f->flags&SF_APPEND)
69 return f->extent + (f->next - f->data);
72 if((f->flags&(SF_SHARE|SF_PUBLIC)) == (SF_SHARE|SF_PUBLIC))
73 { if((s = SFSK(f,0L,1,f->disc)) < 0)
77 s = f->here + (f->next - f->data);
78 return s >= f->extent ? s : f->extent;