O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
close.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
17#include "o2s/log.h"
18
19#include <errno.h>
20#include <stdlib.h> // free
21#include <string.h> // strerror
22#include <unistd.h> // close
23
31{
32 istream_close(&file->stream);
33 if (!file->opened)
34 {
35 log_warning("Attempting to close a file that isn't open.");
36 return;
37 }
38 if (close(file->descriptor) != 0)
39 {
40 log_error("Unable to close the file: %s", strerror(errno));
41 return;
42 }
43 file->opened = false;
44}
void file_close(ifstream_t *file)
Release resources to the system.
Definition close.c:30
Buffered file reader.
void istream_close(istream_t *self)
Free the buffer.
Definition input.c:28
Simplistic logging utilities.
#define log_warning(...)
Report an usual condition, not significant enough to abort the current operation.
Definition log.h:76
#define log_error(...)
Report a condition causing the current operation to abort.
Definition log.h:83
Dynamic string implementation.
File Input Stream.
bool opened
Is this file still open ?
int descriptor
Underlying file.
istream_t stream
Inherit from input stream.