C Streams Library
Download or clone the repository. Put it in a folder on your hard drive.
On Mac OS X, linux, BSD, or any Unix-based system, copy the headers into /usr/local/include.
Compiler flags.
-I or /I, for gcc or clang, and msvc respectively, and then use paths C:/Path/To/The/Library/CubedProgrammerCInputOutput/lib C:/Path/To/The/Library/CubedProgrammerCInputOutput/header_only_include, both are required, on windows.
gcc -O3 -I./include -I./header_only_include -c src/cpcio_fstream.c src/cpcio_istream.c src/cpcio_ostream.c src/cpcio_sstream.c src/cpcio_stdstream.c -fPIC
gcc -shared -o libcpcio.so cpcio_fstream.o cpcio_istream.o cpcio_ostream.o cpcio_sstream.o cpcio_stdstream.o -lm
or
clang -O3 -I./include -I./header_only_include -c src/cpcio_fstream.c src/cpcio_istream.c src/cpcio_ostream.c src/cpcio_sstream.c src/cpcio_stdstream.c -fPIC
clang -shared -o libcpcio.so cpcio_fstream.o cpcio_istream.o cpcio_ostream.o cpcio_sstream.o cpcio_stdstream.o -lm
File: cpcio_istream.h
struct cpcio____istream
cpcio_istream (aka struct cpcio____istream*)
eof flag for cpcio_istream indicates if the eof has been reached, is->eof is true if eof has been reached.
Param is is a cpcio_istream.
Closes a cpcio_istream, returns zero on success.
Param src is a void pointer, data will be read from it in some way.
Param reader is a pointer to a function, it will return the number of chars read and take in three parameters. The first parameter is a void pointer, which will be src. The second parameter is a char pointer, an array to store read chars in. The third parameter is a size type, the length of the array and the number of chars to try to read.
Param close is a pointer to a function, it must return zero on success, and take in a void pointer as a parameter, which will be src.
Opens a cpcio_istream.
Param is is a cpcio_istream.
Param buf is a void pointer to a buffer, the data will be written to it.
Param sz is the number of bytes to read.
Reads up to sz bytes and returns the number of bytes read, stores the data in buf.
Toggles whether or not to use buffered input.
This should only be used to disable buffering before reading any input, or enabling buffering.
Disabling buffering may cause any unread data in the buffer to become lost.
Param is is a cpcio_istream.
Reads a single character from the stream, or 0xff if eof has been reached.
Puts the last read character back, only works if buffer is available.
Param is is a cpcio_istream.
Reads a token from the stream, returns an empty string if eof has been reached.
Param is is a cpcio_istream.
Param s is the delim to use.
Sets the delimiter for token based input
Param is is a cpcio_istream.
Gets the delimiter.
Param is is a cpcio_istream.
Reads an int from the stream.
Param is is a cpcio_istream.
Reads a long from the stream.
Param is is a cpcio_istream.
Reads a long long from the stream.
Param is is a cpcio_istream.
Reads an unsigned long long from the stream.
Param is is a cpcio_istream.
Reads a float from the stream.
Param is is a cpcio_istream.
Reads a double from the stream
Checks if there are bytes ready to read.
If return value is true, then there is data to read.
Otherwise, either end of stream has been reached or the stream has to wait for data to be sent.
File: cpcio_ostream.h
struct cpcio____ostream
cpcio_ostream (aka struct cpcio____ostream*)
Param os is a cpcio_ostream.
Flushes the cpcio_ostream.
Param os is a cpcio_ostream.
Closes the stream, returns zero if successful.
Param src is a void pointer, data will be written to it in some way.
Param writer is a pointer to a function, it will return the number of chars written and take in three parameters. The first parameter is a void pointer, which will be src. The second parameter is a char pointer, an array to write. The third parameter is a size type, the length of the array.
Param close is a pointer to a function, it must return zero on success, and take in a void pointer as a parameter, which will be src.
Opens a cpcio_ostream.
Param os is a cpcio_ostream.
Param buf is a const void pointer to a buffer, the data that will be written.
Param sz is the number of bytes to write.
Writes up to sz bytes and returns the number of bytes written.
Toggles whether or not to buffer the output.
Toggling off will cause the buffer to be flushed.
Param os is a cpcio_ostream.
Writes a single charater to the cpcio_ostream.
Param os is a cpcio_ostream.
Prints a string to the cpcio_ostream.
Param os is a cpcio_ostream.
Prints a string to the cpcio_ostream with a \n.
Param os is a cpcio_ostream.
Params begin and end are iterators that point to strings.
Prints the sequence to a cpcio_ostream, each item is space separated, and a \n is put at the end.
Param os is a cpcio_ostream.
Param i is an int.
Prints an int to the cpcio_ostream.
Param os is a cpcio_ostream.
Param l is a long.
Prints a long to the cpcio_ostream.
Param os is a cpcio_ostream.
Param ll is a long long.
Prints a long long to the cpcio_ostream.
Param os is a cpcio_ostream.
Param ull is a unsigned long long.
Prints an unsigned long long to the cpcio_ostream.
Param os is a cpcio_ostream.
Param f is a float.
Prints a float to the cpcio_ostream.
Param os is a cpcio_ostream.
Param d is a double.
Prints a double to the cpcio_ostream.
Param os is a cpcio_ostream.
Param i is an int.
Prints an int to the cpcio_ostream with a new line.
Param os is a cpcio_ostream.
Param l is a long.
Prints a long to the cpcio_ostream with a new line.
Param os is a cpcio_ostream.
Param ll is a long long.
Prints a long long to the cpcio_ostream with a new line.
Param os is a cpcio_ostream.
Param ull is a unsigned long long.
Prints an unsigned long long to the cpcio_ostream with a new line.
Param os is a cpcio_ostream.
Param f is a float.
Prints a float to the cpcio_ostream with a new line.
Param os is a cpcio_ostream.
Param d is a double.
Prints a double to the cpcio_ostream with a new line.
File: cpcio_sstream.h
String streams header. There are input string streams and output string streams.
This header does offer new structs but they are not important for the user to know.
Param str is a string to read from.
Opens an istringstream that reads from a string.
Param arr is a char array.
Param n is the size of the array.
Opens an istringstream that reads from a string.
Opens a ostringstream that writes to a string.
Param oss is a pointer to an ostringstream.
Gets the string from the ostringstream.
File: cpcio_fstream.h
File streams header, for reading and writing to files.
This header does not offer any structs.
Param s is the file name.
Opens a cpcio_istream that reads from a file.
Param s is a filename.
Param m is the mode, either w for write or a for append.
Opens a cpcio_ostream that writes to a file.
File: cpcio_stdstream.h
File streams header, for reading and writing to files.
This header does not offer any structs.
Gets a cpcio_istream that reads from stdin.
Gets a cpcio_ostream that reads from stdout.
Gets a cpcio_ostream that reads from stderr.