view src/ploki/IO.h @ 8916:0234daffd946

<oerjan> addquote <int-e> I couldn\'t help thinking that maybe if one considers the ramifications in full detail it will turn out that overthinking is often not helpful and therefore, not something to be proud of.
author HackBot
date Sun, 14 Aug 2016 02:31:47 +0000
parents ac0403686959
children
line wrap: on
line source

#ifndef IO_H_
#define IO_H_

#include "config.h"
#include "Str.h"

#include <stdio.h>

typedef struct IO IO;

enum io_flags {
	IO_BINARY    = 1,
	IO_READ      = 2 * IO_BINARY,
	IO_WRITE     = 2 * IO_READ,
	IO_APPEND    = 2 * IO_WRITE,
	IO_TRUNCATE  = 2 * IO_APPEND,
	IO_BUFFERED  = 2 * IO_TRUNCATE,
	IO_AUTOFLUSH = 2 * IO_BUFFERED
};

enum io_whence {
	IOS_START = SEEK_SET,
	IOS_CUR   = SEEK_CUR,
	IOS_END   = SEEK_END
};

void io_init(void);
void io_end(void);
const char *io_name(const IO *, String *);
IO *io_enter(const char *, FILE *, enum io_flags);
IO *io_open(const char *, enum io_flags);
IO *io_incr(IO *);
void io_decr(IO *);
int io_close(IO *);

ATTR_PURE
int io_bufred(const IO *);
void io_unbuffer(IO *);
const char *io_bufptr(IO *);

ATTR_PURE
FILE *io_fp(const IO *);

int io_flush(IO *);
ATTR_PURE
int io_err(const IO *);
ATTR_PURE
int io_eof(const IO *);
int io_peek(IO *, size_t);
int io_cmppeek(IO *, size_t, const void *, size_t);
int io_xcmp(IO *, size_t, size_t, size_t);

size_t io_read(IO *, String *, size_t);
int io_getc(IO *);
size_t io_getline(IO *, String *);
size_t io_write(IO *, const String *);
size_t io_write_m(IO *, const void *, size_t);
size_t io_write_s(IO *, const char *);
int io_putc(IO *, int);

long io_tell(IO *);
int io_seek(IO *, long, enum io_whence);
void io_clearerr(IO *);

#endif /* IO_H_ */