GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
STRING_FP(3) FreeBSD Library Functions Manual STRING_FP(3)

string_buf_input, string_buf_output, string_buf_content, string_buf_length
string buffer streams

PDEL Library (libpdel, -lpdel)

#include <sys/types.h>
#include <stdio.h>
#include <pdel/io/string_fp.h>

FILE *
string_buf_input(const void *buf, size_t len, int copy);

FILE *
string_buf_output(const void *mtype);

char *
string_buf_content(FILE *fp, int reset);

int
string_buf_length(FILE *fp);

These functions allow string buffers to be read and written as streams.

string_buf_input() creates a read-only stream that reads from the buffer pointed to by buf having length len. If copy is non-zero, the contents of the buffer are copied and therefore buf doesn't need to remain valid while the stream is open. Otherwise, the data pointed to by buf is not copied and must remain valid while the stream is open. fclose(3) should be used to close the stream.

string_buf_output() creates a write-only stream that writes into an internal buffer that grows dynamically. fclose(3) should be used to close the stream; this also frees the internal buffer. The current buffer length is returned by string_buf_length().

string_buf_content() returns the contents of the internal buffer. As with string_buf_length(), the fp argument must be a stream created by string_buf_output(). If reset is zero, then the internal buffer remains valid and the returned pointer should be treated as read-only and not be freed; it also becomes invalid with the next operation on the stream. If reset is non-zero, the current buffer contents are "detached" and returned by string_buf_content(), and a new, empty internal buffer is created; in this case, the caller is responsible for eventually freeing the returned buffer, which is allocated with typed_mem(3) type mtype, and its contents remain valid until then.

In either case, the data returned by string_buf_content() is guaranteed to have one additional '\0' byte appended. Therefore, it is always safe to treat this pointer as a normal C string. However, any '\0' bytes previously written to the stream will cause this string to appear truncated.

string_buf_input(), string_buf_output(), and string_buf_content() return NULL to indicate an error, with errno set appropriately.

Even if string_buf_content() returns NULL, the stream will still need to be closed.

string_buf_content() and string_buf_length() attempt to verify that the supplied stream was indeed created by string_buf_output(). If they detect otherwise, an immediate assertion failure is generated.

base64(3), filter(3), fopen(3), libpdel(3), typed_mem(3)

The PDEL library was developed at Packet Design, LLC. http://www.packetdesign.com/

Archie Cobbs ⟨archie@freebsd.org⟩
April 22, 2002 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.