Annotation of embedaddon/libpdel/io/string_fp.3, revision 1.1
1.1 ! misho 1: .\" Copyright (c) 2001-2002 Packet Design, LLC.
! 2: .\" All rights reserved.
! 3: .\"
! 4: .\" Subject to the following obligations and disclaimer of warranty,
! 5: .\" use and redistribution of this software, in source or object code
! 6: .\" forms, with or without modifications are expressly permitted by
! 7: .\" Packet Design; provided, however, that:
! 8: .\"
! 9: .\" (i) Any and all reproductions of the source or object code
! 10: .\" must include the copyright notice above and the following
! 11: .\" disclaimer of warranties; and
! 12: .\" (ii) No rights are granted, in any manner or form, to use
! 13: .\" Packet Design trademarks, including the mark "PACKET DESIGN"
! 14: .\" on advertising, endorsements, or otherwise except as such
! 15: .\" appears in the above copyright notice or in the software.
! 16: .\"
! 17: .\" THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
! 18: .\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
! 19: .\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
! 20: .\" THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
! 21: .\" WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
! 22: .\" OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
! 23: .\" OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
! 24: .\" OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
! 25: .\" RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
! 26: .\" LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
! 27: .\" OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
! 28: .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
! 29: .\" DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
! 30: .\" USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
! 31: .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 32: .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
! 33: .\" THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
! 34: .\" THE POSSIBILITY OF SUCH DAMAGE.
! 35: .\"
! 36: .\" Author: Archie Cobbs <archie@freebsd.org>
! 37: .\"
! 38: .\" $Id: string_fp.3,v 1.8 2004/06/02 17:24:37 archie Exp $
! 39: .\"
! 40: .Dd April 22, 2002
! 41: .Dt STRING_FP 3
! 42: .Os
! 43: .Sh NAME
! 44: .Nm string_buf_input ,
! 45: .Nm string_buf_output ,
! 46: .Nm string_buf_content ,
! 47: .Nm string_buf_length
! 48: .Nd string buffer streams
! 49: .Sh LIBRARY
! 50: PDEL Library (libpdel, \-lpdel)
! 51: .Sh SYNOPSIS
! 52: .In sys/types.h
! 53: .In stdio.h
! 54: .In pdel/io/string_fp.h
! 55: .Ft "FILE *"
! 56: .Fn string_buf_input "const void *buf" " size_t len" "int copy"
! 57: .Ft "FILE *"
! 58: .Fn string_buf_output "const void *mtype"
! 59: .Ft "char *"
! 60: .Fn string_buf_content "FILE *fp" "int reset"
! 61: .Ft "int"
! 62: .Fn string_buf_length "FILE *fp"
! 63: .Sh DESCRIPTION
! 64: These functions allow string buffers to be read and written as streams.
! 65: .Pp
! 66: .Fn string_buf_input
! 67: creates a read-only stream that reads from the buffer pointed to by
! 68: .Fa buf
! 69: having length
! 70: .Fa len .
! 71: If
! 72: .Fa copy
! 73: is non-zero, the contents of the buffer are copied and therefore
! 74: .Fa buf
! 75: doesn't need to remain valid while the stream is open.
! 76: Otherwise, the data pointed to by
! 77: .Fa buf
! 78: is not copied and must remain valid while the stream is open.
! 79: .Xr fclose 3
! 80: should be used to close the stream.
! 81: .Pp
! 82: .Fn string_buf_output
! 83: creates a write-only stream that writes into an internal buffer that
! 84: grows dynamically.
! 85: .Xr fclose 3
! 86: should be used to close the stream; this also frees the internal buffer.
! 87: The current buffer length is returned by
! 88: .Fn string_buf_length .
! 89: .Pp
! 90: .Fn string_buf_content
! 91: returns the contents of the internal buffer.
! 92: As with
! 93: .Fn string_buf_length ,
! 94: the
! 95: .Fa fp
! 96: argument must be a stream created by
! 97: .Fn string_buf_output .
! 98: If
! 99: .Fa reset
! 100: is zero, then the internal buffer remains valid and the returned pointer
! 101: should be treated as read-only and not be freed; it also becomes invalid
! 102: with the next operation on the stream.
! 103: If
! 104: .Fa reset
! 105: is non-zero, the current buffer contents are "detached" and returned by
! 106: .Fn string_buf_content ,
! 107: and a new, empty internal buffer is created; in this case, the caller is
! 108: responsible for eventually freeing the returned buffer,
! 109: which is allocated with
! 110: .Xr typed_mem 3
! 111: type
! 112: .Fa mtype ,
! 113: and its contents remain valid until then.
! 114: .Pp
! 115: In either case, the data returned by
! 116: .Fn string_buf_content
! 117: is guaranteed to have one additional '\\0' byte appended.
! 118: Therefore, it is always safe to treat this pointer as a normal C string.
! 119: However, any '\\0' bytes previously written to the stream will cause
! 120: this string to appear truncated.
! 121: .Sh RETURN VALUES
! 122: .Fn string_buf_input ,
! 123: .Fn string_buf_output ,
! 124: and
! 125: .Fn string_buf_content
! 126: return
! 127: .Dv NULL
! 128: to indicate an error, with
! 129: .Va errno
! 130: set appropriately.
! 131: .Pp
! 132: Even if
! 133: .Fn string_buf_content
! 134: returns
! 135: .Dv NULL ,
! 136: the stream will still need to be closed.
! 137: .Sh IMPLEMENTATION NOTES
! 138: .Fn string_buf_content
! 139: and
! 140: .Fn string_buf_length
! 141: attempt to verify that the supplied stream was indeed created by
! 142: .Fn string_buf_output .
! 143: If they detect otherwise, an immediate assertion failure is generated.
! 144: .Sh SEE ALSO
! 145: .Xr base64 3 ,
! 146: .Xr filter 3 ,
! 147: .Xr fopen 3 ,
! 148: .Xr libpdel 3 ,
! 149: .Xr typed_mem 3
! 150: .Sh HISTORY
! 151: The PDEL library was developed at Packet Design, LLC.
! 152: .Dv "http://www.packetdesign.com/"
! 153: .Sh AUTHORS
! 154: .An Archie Cobbs Aq archie@freebsd.org
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>