---
name: "stream_open"
section: "3abz"
platform: "linux"
package: "libabz0-dev"
version: "0.5.1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/stream_open"
---

# stream\_open(3abz)

cached I/O operations.

## NAME

stream\_open, stream\_read, stream\_getline, stream\_write, stream\_close - cached I/O operations.

## LIBRARIES

Abz Library (-labz), Debug Library (-ldebug)

## SYNOPSIS

```
#include <abz/stream.h>

void stream_open(struct stream *stream, int fd);
ssize_t stream_read(struct stream *stream, void *buf, size_t count);
ssize_t stream_getline(struct stream *stream, char **buf);
ssize_t stream_write(struct stream *stream, const char *buf, size_t count);
void stream_close(struct stream *stream);
```

## DESCRIPTION

These functions perform I/O operations on a file descriptor and possibly caches read data. These functions should not be mixed with calls to **read()** or **write()**.

**stream\_open()** initializes the stream structure. It should be called before any of the other functions. The *fd* parameter should be an open file descriptor.

**stream\_read()** attempts to read up to *count* bytes from the stream into the buffer starting at *buf*. If *count* is zero, **read()** returns zero and has no other results. If *count* is greater than SSIZE\_MAX, the result is unspecified.

**stream\_getline()** reads exactly one line of data, including the trailing '0 from the stream. It allocates memory for, and stores the result in *buf*. This function should only be called on file descriptors with blocking I/O selected as it will only return when a newline character is found or at the end of a file.

**stream\_write()** writes up to *count* bytes to the file referenced by the file descriptor *fd* from the buffer starting at *buf*.

**stream\_close()** free resources allocated for the stream and close and the file descriptor.

## RETURN VALUES

Except for **stream\_open()** and **stream\_close()**, all of these functions return the number of bytes transferred or -1 if an error occurred. Call **abz\_get\_error()** to retrieve error messages.

## NOTES

None of the libabz routines are thread-safe. I'm not planning to change this either! For more information, please see http://threading.2038bug.com/

## SEE ALSO

abz\_get\_error(3)

## AUTHOR

Written by Abraham vd Merwe \<abz@blio.com\>
