version 1.3, 1996/06/26 05:36:25 |
version 1.4, 1996/11/30 21:08:50 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
/* $NetBSD: buf.c,v 1.7 1996/03/29 02:17:13 jtc Exp $ */ |
/* $NetBSD: buf.c,v 1.8 1996/11/06 17:59:00 christos Exp $ */ |
|
|
/* |
/* |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
|
|
|
|
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char sccsid[] = "@(#)buf.c 5.5 (Berkeley) 12/28/90"; |
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93"; |
#else |
#else |
static char rcsid[] = "$OpenBSD$"; |
static char rcsid[] = "$OpenBSD$"; |
#endif |
#endif |
|
|
Buf_AddBytes (bp, numBytes, bytesPtr) |
Buf_AddBytes (bp, numBytes, bytesPtr) |
register Buffer bp; |
register Buffer bp; |
int numBytes; |
int numBytes; |
Byte *bytesPtr; |
const Byte *bytesPtr; |
{ |
{ |
|
|
BufExpand (bp, numBytes); |
BufExpand (bp, numBytes); |
|
|
int numBytes; |
int numBytes; |
Byte *bytesPtr; |
Byte *bytesPtr; |
{ |
{ |
|
|
if (bp->inPtr - bp->outPtr < numBytes) { |
if (bp->inPtr - bp->outPtr < numBytes) { |
numBytes = bp->inPtr - bp->outPtr; |
numBytes = bp->inPtr - bp->outPtr; |
} |
} |
|
|
if (numBytesPtr != (int *)NULL) { |
if (numBytesPtr != (int *)NULL) { |
*numBytesPtr = bp->inPtr - bp->outPtr; |
*numBytesPtr = bp->inPtr - bp->outPtr; |
} |
} |
|
|
return (bp->outPtr); |
return (bp->outPtr); |
} |
} |
|
|
|
|
* None. |
* None. |
* |
* |
* Side Effects: |
* Side Effects: |
* The bytes are discarded. |
* The bytes are discarded. |
* |
* |
*----------------------------------------------------------------------- |
*----------------------------------------------------------------------- |
*/ |
*/ |
|
|
Buffer buf; /* Buffer to destroy */ |
Buffer buf; /* Buffer to destroy */ |
Boolean freeData; /* TRUE if the data should be destroyed as well */ |
Boolean freeData; /* TRUE if the data should be destroyed as well */ |
{ |
{ |
|
|
if (freeData) { |
if (freeData) { |
free ((char *)buf->buffer); |
free ((char *)buf->buffer); |
} |
} |
free ((char *)buf); |
free ((char *)buf); |
|
} |
|
|
|
/*- |
|
*----------------------------------------------------------------------- |
|
* Buf_ReplaceLastByte -- |
|
* Replace the last byte in a buffer. |
|
* |
|
* Results: |
|
* None. |
|
* |
|
* Side Effects: |
|
* If the buffer was empty intially, then a new byte will be added. |
|
* Otherwise, the last byte is overwritten. |
|
* |
|
*----------------------------------------------------------------------- |
|
*/ |
|
void |
|
Buf_ReplaceLastByte (buf, byte) |
|
Buffer buf; /* buffer to augment */ |
|
Byte byte; /* byte to be written */ |
|
{ |
|
if (buf->inPtr == buf->outPtr) |
|
Buf_AddByte(buf, byte); |
|
else |
|
*(buf->inPtr - 1) = byte; |
} |
} |