1 /* $XConsortium: sfpeek.c /main/3 1995/11/01 18:32:14 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 /* Safe access to the internal stream buffer.
27 ** This function is obsolete. sfreserve() should be used.
29 ** Written by Kiem-Phong Vo (06/27/90).
33 sfpeek(reg Sfio_t* f, Void_t** bp, reg int size)
36 reg Sfio_t* f; /* file to peek */
37 Void_t** bp; /* start of data area */
38 reg int size; /* size of peek */
42 /* query for the extent of the remainder of the buffer */
47 if((f->flags&SF_RDWRSTR) == SF_RDWRSTR)
49 n = (f->data+f->here) - f->next;
51 else n = f->endb - f->next;
55 else if(n > 0) /* size == 0 */
56 { *bp = (Void_t*)f->next;
59 /* else fall down and fill buffer */
62 if(!(n = f->flags&SF_READ) )
64 if(f->mode != n && _sfmode(f,n,0) < 0)
67 *bp = sfreserve(f, size <= 0 ? 0 : size > f->size ? f->size : size, 0);
72 if((n = sfslen()) > 0)
73 { *bp = (Void_t*)f->next;
76 f->endr = f->endw = f->data;
85 return (size >= 0 && n >= size) ? size : n;