/usr/include/snacc/c/sbuf.h is in libsnacc-dev 1.3.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | /*
* sbuf.h - a buffer consisting of one contiguous block
* that checks for read and write range errors.
* MS 92
* Copyright (C) 1992 Michael Sample and the University of British Columbia
*
* This library is free software; you can redistribute it and/or
* modify it provided that this copyright/license information is retained
* in original form.
*
* If you modify this file, you must clearly indicate your changes.
*
* This source code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Header: /usr/app/odstb/CVS/snacc/c-lib/inc/sbuf.h,v 1.2 1995/07/27 08:54:46 rj Exp $
* $Log: sbuf.h,v $
* Revision 1.2 1995/07/27 08:54:46 rj
* functions used by gen-bufs or type tables merged.
*
* changed `_' to `-' in file names.
*
* Revision 1.1 1994/08/28 09:45:39 rj
* first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
*
*/
#ifndef _asn_buf_h_
#define _asn_buf_h_
typedef struct SBuf
{
char *dataStart; /* byte last written (or end) */
char *dataEnd; /* ptr to first byte after last valid data byte */
char *blkStart; /* ptr to first byte of the buffer */
char *blkEnd; /* ptr to first byte past end of the buffer */
char *readLoc; /* next byte to read (or end) */
int writeError; /* whether write error occurred */
int readError; /* whether read error occurred */
} SBuf;
#ifdef USE_GEN_BUF
/* use functions (-> src/sbuf.c) instead of cpp macros */
void PutSBufInGenBuf PROTO ((SBuf *sb, GenBuf *gb));
void SBufInit PROTO ((SBuf *b, char *data, long int dataLen));
void SBufResetInReadMode PROTO ((SBuf *b));
void SBufResetInWriteRvsMode PROTO ((SBuf *b));
void SBufInstallData PROTO ((SBuf *b, char *data, long int dataLen));
long int SBufDataLen PROTO ((SBuf *b));
char *SBufDataPtr PROTO ((SBuf *b));
long int SBufBlkLen PROTO ((SBuf *b));
char *SBufBlkPtr PROTO ((SBuf *b));
int SBufEod PROTO ((SBuf *b));
int SBufReadError PROTO ((SBuf *b));
int SBufWriteError PROTO ((SBuf *b));
void SBufSkip PROTO ((SBuf *b, long int skipLen));
void SBufCopy PROTO ((char *dst, SBuf *b, long int copyLen));
unsigned char SBufPeekByte PROTO ((SBuf *b));
#if TTBL
char *SBufPeekSeg PROTO ((SBuf *b, long int *lenPtr));
void SBufPeekCopy PROTO ((char *dst, SBuf *b, long int copyLen));
#endif
char *SBufGetSeg PROTO ((SBuf *b,long int *lenPtr));
void SBufPutSegRvs PROTO ((SBuf *b, char *seg, long int segLen));
unsigned char SBufGetByte PROTO ((SBuf *b));
void SBufPutByteRvs PROTO ((SBuf *b, unsigned char byte));
#else
/* initializes a buffer into an 'empty' state */
#define SBufInit(b, data, dataLen)\
{ (b)->readError = (b)->writeError = 1;\
(b)->blkStart = data;\
(b)->blkEnd = data + dataLen;\
(b)->dataStart = (b)->dataEnd = (b)->readLoc = (b)->blkEnd;\
}
#define SBufResetInReadMode(b)\
{ (b)->readLoc = (b)->dataStart;\
(b)->readError = 0;\
(b)->writeError = 1;\
}
#define SBufResetInWriteRvsMode(b)\
{ (b)->dataStart = (b)->dataEnd = (b)->blkEnd;\
(b)->writeError = 0;\
(b)->readError = 1;\
}
/* installs given block of data into a buffer and sets it up for reading */
#define SBufInstallData(b, data, dataLen)\
SBufInit (b, data, dataLen);\
(b)->dataStart = (b)->blkStart;\
SBufResetInReadMode (b);
/* returns the number of bytes in the data portion */
#define SBufDataLen(b)\
((b)->dataEnd - (b)->dataStart)
/* returns the pointer to the first data byte */
#define SBufDataPtr(b)\
((b)->dataStart)
/* returns the size of block, the maximum size for data */
#define SBufBlkLen(b)\
((b)->blkEnd - (b)->blkStart)
/* returns a pointer to the first byte of the block */
#define SBufBlkPtr(b)\
((b)->blkStart)
/* returns true if there is no more data to be read in the SBuf */
#define SBufEod(b)\
((b)->readLoc >= (b)->dataEnd)
/* returns true if you attempted to read past the end of data */
#define SBufReadError(b)\
((b)->readError)
/*
* returns true if you attempted to write past the end of the block
* (remember SBufs do not expand like ExpBufs)
*/
#define SBufWriteError(b)\
((b)->writeError)
/* Skips the next skipLen bytes for reading */
#define SBufSkip(b, skipLen)\
{ if ( ((b)->readLoc + skipLen) > (b)->dataEnd)\
{\
(b)->readLoc = (b)->dataEnd;\
(b)->readError = 1;\
}\
else\
(b)->readLoc += skipLen;\
}
/*
* copies copyLen bytes from buffer b into char *dst.
* assumes dst is pre-allocated and is large enough.
* Will set the read error flag is you attempt to copy
* more than the number of unread bytes available.
*/
#define SBufCopy(dst, b, copyLen)\
{ if (((b)->readLoc + copyLen) > (b)->dataEnd)\
{\
memcpy (dst, (b)->readLoc, (b)->dataEnd - (b)->readLoc);\
(b)->readLoc = (b)->dataEnd;\
(b)->readError = 1;\
}\
else\
{\
memcpy (dst, (b)->readLoc, copyLen);\
(b)->readLoc += copyLen;\
}\
}
/*
* returns the next byte from the buffer without advancing the
* current read location.
*/
#define SBufPeekByte(b)\
((SBufEod (b))? ((b)->readError = 1):(unsigned char) *((b)->readLoc))
/*
* WARNING: this is a fragile macro. be careful where you use it.
* return a pointer into the buffer for the next bytes to be read
* if *lenPtr uread bytes are not available, *lenPtr will be set
* to the number of byte that are available. The current read location
* is advance by the number of bytes returned in *lenPtr. The read error
* flag will NOT set, ever, by this routine.
*/
#define SBufGetSeg( b, lenPtr)\
((b)->readLoc);\
if (((b)->readLoc + *lenPtr) > (b)->dataEnd)\
{\
*lenPtr = (b)->dataEnd - (b)->readLoc;\
(b)->readLoc = (b)->dataEnd;\
}\
else\
(b)->readLoc += *lenPtr;
/*
* Write in reverse the char *seg of segLen bytes to the buffer b.
* A reverse write of segement really just prepends the given seg
* (in original order) to the buffers existing data
*/
#define SBufPutSegRvs(b, seg, segLen)\
{ if (((b)->dataStart - segLen) < (b)->blkStart)\
(b)->writeError = 1;\
else\
{\
(b)->dataStart -= segLen;\
memcpy ((b)->dataStart, seg, segLen);\
}\
}
/*
* returns the next byte from buffer b's data and advances the
* current read location by one byte. This will set the read error
* flag if you attempt to read past the end of the SBuf
*/
#define SBufGetByte(b)\
(unsigned char)((SBufEod (b))? ((b)->readError = 1):*((b)->readLoc++))
/*
* writes (prepends) the given byte to buffer b's data
*/
#define SBufPutByteRvs(b, byte)\
{ if ((b)->dataStart <= (b)->blkStart)\
(b)->writeError = 1;\
else\
*(--(b)->dataStart) = byte;\
}
#endif /* USE_GEN_BUF */
#endif /* conditional include */
|