1da2e3ebdSchin /*********************************************************************** 2da2e3ebdSchin * * 3da2e3ebdSchin * This software is part of the ast package * 4*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property * 5da2e3ebdSchin * and is licensed under the * 6da2e3ebdSchin * Common Public License, Version 1.0 * 77c2fbfb3SApril Chin * by AT&T Intellectual Property * 8da2e3ebdSchin * * 9da2e3ebdSchin * A copy of the License is available at * 10da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt * 11da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12da2e3ebdSchin * * 13da2e3ebdSchin * Information and Software Systems Research * 14da2e3ebdSchin * AT&T Research * 15da2e3ebdSchin * Florham Park NJ * 16da2e3ebdSchin * * 17da2e3ebdSchin * Glenn Fowler <gsf@research.att.com> * 18da2e3ebdSchin * David Korn <dgk@research.att.com> * 19da2e3ebdSchin * Phong Vo <kpv@research.att.com> * 20da2e3ebdSchin * * 21da2e3ebdSchin ***********************************************************************/ 22da2e3ebdSchin #ifndef _SFIO_T_H 23da2e3ebdSchin #define _SFIO_T_H 1 24da2e3ebdSchin 25da2e3ebdSchin /* This header file is for library writers who need to know certain 26da2e3ebdSchin ** internal info concerning the full Sfio_t structure. Including this 27da2e3ebdSchin ** file means that you agree to track closely with sfio development 28da2e3ebdSchin ** in case its internal architecture is changed. 29da2e3ebdSchin ** 30da2e3ebdSchin ** Written by Kiem-Phong Vo 31da2e3ebdSchin */ 32da2e3ebdSchin 33da2e3ebdSchin /* the parts of Sfio_t private to sfio functions */ 34da2e3ebdSchin #define _SFIO_PRIVATE \ 35da2e3ebdSchin Sfoff_t extent; /* current file size */ \ 36da2e3ebdSchin Sfoff_t here; /* current physical location */ \ 37da2e3ebdSchin unsigned char getr; /* the last sfgetr separator */ \ 38da2e3ebdSchin unsigned char tiny[1];/* for unbuffered read stream */ \ 39da2e3ebdSchin unsigned short bits; /* private flags */ \ 40da2e3ebdSchin unsigned int mode; /* current io mode */ \ 41da2e3ebdSchin struct _sfdisc_s* disc; /* discipline */ \ 42da2e3ebdSchin struct _sfpool_s* pool; /* the pool containing this */ \ 43da2e3ebdSchin struct _sfrsrv_s* rsrv; /* reserved buffer */ \ 44da2e3ebdSchin struct _sfproc_s* proc; /* coprocess id, etc. */ \ 45da2e3ebdSchin Void_t* mutex; /* mutex for thread-safety */ \ 46da2e3ebdSchin Void_t* stdio; /* stdio FILE if any */ \ 47da2e3ebdSchin Sfoff_t lpos; /* last seek position */ \ 48da2e3ebdSchin size_t iosz; /* preferred size for I/O */ \ 49da2e3ebdSchin size_t blksz; /* preferred block size */ \ 50da2e3ebdSchin Void_t* fill[1];/* modest expansion */ 51da2e3ebdSchin 52da2e3ebdSchin #include "sfio.h" 53da2e3ebdSchin 54da2e3ebdSchin /* mode bit to indicate that the structure hasn't been initialized */ 55da2e3ebdSchin #define SF_INIT 0000004 56da2e3ebdSchin #define SF_DCDOWN 00010000 57da2e3ebdSchin 58da2e3ebdSchin /* short-hand for common stream types */ 59da2e3ebdSchin #define SF_RDWR (SF_READ|SF_WRITE) 60da2e3ebdSchin #define SF_RDSTR (SF_READ|SF_STRING) 61da2e3ebdSchin #define SF_WRSTR (SF_WRITE|SF_STRING) 62da2e3ebdSchin #define SF_RDWRSTR (SF_RDWR|SF_STRING) 63da2e3ebdSchin 64da2e3ebdSchin /* for static initialization of an Sfio_t structure */ 65da2e3ebdSchin #define SFNEW(data,size,file,type,disc,mutex) \ 66da2e3ebdSchin { (unsigned char*)(data), /* next */ \ 67da2e3ebdSchin (unsigned char*)(data), /* endw */ \ 68da2e3ebdSchin (unsigned char*)(data), /* endr */ \ 69da2e3ebdSchin (unsigned char*)(data), /* endb */ \ 70da2e3ebdSchin (Sfio_t*)0, /* push */ \ 71da2e3ebdSchin (unsigned short)((type)&SF_FLAGS), /* flags */ \ 72da2e3ebdSchin (short)(file), /* file */ \ 73da2e3ebdSchin (unsigned char*)(data), /* data */ \ 74da2e3ebdSchin (ssize_t)(size), /* size */ \ 75da2e3ebdSchin (ssize_t)(-1), /* val */ \ 76da2e3ebdSchin (Sfoff_t)0, /* extent */ \ 77da2e3ebdSchin (Sfoff_t)0, /* here */ \ 78da2e3ebdSchin 0, /* getr */ \ 79da2e3ebdSchin {0}, /* tiny */ \ 80da2e3ebdSchin 0, /* bits */ \ 81da2e3ebdSchin (unsigned int)(((type)&(SF_RDWR))|SF_INIT), /* mode */ \ 82da2e3ebdSchin (struct _sfdisc_s*)(disc), /* disc */ \ 83da2e3ebdSchin (struct _sfpool_s*)0, /* pool */ \ 84da2e3ebdSchin (struct _sfrsrv_s*)0, /* rsrv */ \ 85da2e3ebdSchin (struct _sfproc_s*)0, /* proc */ \ 86da2e3ebdSchin (mutex), /* mutex */ \ 87da2e3ebdSchin (Void_t*)0, /* stdio */ \ 88da2e3ebdSchin (Sfoff_t)0, /* lpos */ \ 89da2e3ebdSchin (size_t)0 /* iosz */ \ 90da2e3ebdSchin } 91da2e3ebdSchin 92da2e3ebdSchin /* function to clear an Sfio_t structure */ 93da2e3ebdSchin #define SFCLEAR(f,mtx) \ 94da2e3ebdSchin ( (f)->next = (unsigned char*)0, /* next */ \ 95da2e3ebdSchin (f)->endw = (unsigned char*)0, /* endw */ \ 96da2e3ebdSchin (f)->endr = (unsigned char*)0, /* endr */ \ 97da2e3ebdSchin (f)->endb = (unsigned char*)0, /* endb */ \ 98da2e3ebdSchin (f)->push = (Sfio_t*)0, /* push */ \ 99da2e3ebdSchin (f)->flags = (unsigned short)0, /* flags */ \ 100da2e3ebdSchin (f)->file = -1, /* file */ \ 101da2e3ebdSchin (f)->data = (unsigned char*)0, /* data */ \ 102da2e3ebdSchin (f)->size = (ssize_t)(-1), /* size */ \ 103da2e3ebdSchin (f)->val = (ssize_t)(-1), /* val */ \ 104da2e3ebdSchin (f)->extent = (Sfoff_t)(-1), /* extent */ \ 105da2e3ebdSchin (f)->here = (Sfoff_t)0, /* here */ \ 106da2e3ebdSchin (f)->getr = 0, /* getr */ \ 107da2e3ebdSchin (f)->tiny[0] = 0, /* tiny */ \ 108da2e3ebdSchin (f)->bits = 0, /* bits */ \ 109da2e3ebdSchin (f)->mode = 0, /* mode */ \ 110da2e3ebdSchin (f)->disc = (struct _sfdisc_s*)0, /* disc */ \ 111da2e3ebdSchin (f)->pool = (struct _sfpool_s*)0, /* pool */ \ 112da2e3ebdSchin (f)->rsrv = (struct _sfrsrv_s*)0, /* rsrv */ \ 113da2e3ebdSchin (f)->proc = (struct _sfproc_s*)0, /* proc */ \ 114da2e3ebdSchin (f)->mutex = (mtx), /* mutex */ \ 115da2e3ebdSchin (f)->stdio = (Void_t*)0, /* stdio */ \ 116da2e3ebdSchin (f)->lpos = (Sfoff_t)0, /* lpos */ \ 117da2e3ebdSchin (f)->iosz = (size_t)0 /* iosz */ \ 118da2e3ebdSchin ) 119da2e3ebdSchin 120da2e3ebdSchin /* expose next stream inside discipline function; state saved in int f */ 121da2e3ebdSchin #define SFDCNEXT(sp,f) (((f)=(sp)->bits&SF_DCDOWN),(sp)->bits|=SF_DCDOWN) 122da2e3ebdSchin 123da2e3ebdSchin /* restore SFDCNEXT() state from int f */ 124da2e3ebdSchin #define SFDCPREV(sp,f) ((f)?(0):((sp)->bits&=~SF_DCDOWN)) 125da2e3ebdSchin 126da2e3ebdSchin #endif /* _SFIO_T_H */ 127