O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
file_input_stream.h
Go to the documentation of this file.
1#pragma once
2
3/* ************************************************************************** */
4/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
5/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
6/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
7/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
8/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
9/* */
16/* ************************************************************************** */
17
18#include "o2s/input_stream.h"
19
20#include <signal.h> // siginfo_t
21#include <stdbool.h> // bool
22#include <stdint.h> // uint*_t
23#include <stdio.h> // ssize_t
24
26typedef struct file_input_stream
27{
30 bool opened;
32
35ifstream_t file_open(const char* file_name, int flags);
36ifstream_t file_from_descriptor(int descriptor);
37void file_close(ifstream_t* file);
39
42ssize_t file_single_read(ifstream_t* file);
43bool file_accumulate(ifstream_t* file, size_t count);
44bool file_accumulate_infinite(ifstream_t* file, size_t count);
45
46void file_stop_reading(void);
47void file_resume_reading(void);
49
50void file_default_signal_handler(int, siginfo_t*, void*);
51
68#define FileInputStream __attribute__((cleanup(file_close))) ifstream_t
void file_default_signal_handler(int, siginfo_t *, void *)
Default signal handler.
Definition read.c:112
void file_close(ifstream_t *file)
Release resources to the system.
Definition close.c:30
void file_resume_reading(void)
Resume calling read in this thread.
Definition read.c:106
void file_stop_reading(void)
Prevent the accumulate function from calling read in this thread.
Definition read.c:100
bool file_accumulate_infinite(ifstream_t *file, size_t count)
If possible, accumulate count bytes before returning.
Definition read.c:69
ifstream_t file_from_descriptor(int descriptor)
Construct a file input stream from an externally managed file descriptor.
Definition open.c:54
ifstream_t file_open(const char *file_name, int flags)
Construct a file input stream : Open the file and allocate the buffer.
Definition open.c:35
bool file_accumulate(ifstream_t *file, size_t count)
If possible, accumulate count bytes before returning.
Definition read.c:87
ssize_t file_single_read(ifstream_t *file)
Read as much as possible.
Definition read.c:38
Buffered input streams.
File Input Stream.
bool opened
Is this file still open ?
int descriptor
Underlying file.
istream_t stream
Inherit from input stream.
Input Stream.