htils 1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
file.h
Go to the documentation of this file.
1#ifndef HTILS_FILE_H
2#define HTILS_FILE_H
3
4/***********************************/
5
6#include <stdio.h>
7#include <sys/stat.h>
8
9#include <htils/arena.h>
10#include <htils/basictypes.h>
11#include <htils/string.h>
12
15#if defined(_WIN32)
16#include <windows.h>
17
18#define fileno _fileno
19#define stat _stat64
20#define fstat _fstati64
21#endif
22
23/***********************************/
24
54u64 file_size_stream(FILE *stream);
55
56//
57//
58//
59
73u64 file_size(const string *path);
74
75//
76//
77//
78
98string *read_file_from_stream(arena_t *arena, FILE *stream);
99
100//
101//
102//
103
119string *read_file(arena_t *arena, const string *path);
120
121//
122//
123//
124
146string *read_file_from_stream_bytes(arena_t *arena, FILE *stream,
147 const u64 bytes);
148
149//
150//
151//
152
171string *read_file_bytes(arena_t *arena, const string *path, const u64 bytes);
172
173//
174//
175//
176
197u64 write_to_file_stream(FILE *stream, const string *contents);
198
199//
200//
201//
202
218u64 write_to_file(const string *path, const string *contents);
219
220//
221//
222//
223
246u64 write_to_file_stream_bytes(FILE *stream, const string *contents,
247 const u64 bytes);
248
249//
250//
251//
252
271u64 write_to_file_bytes(const string *path, const string *contents,
272 const u64 bytes);
273
274#endif // !HTILS_FILE_H
struct arena arena_t
An atomic arena.
uint64_t u64
Definition basictypes.h:22
string * read_file_from_stream(arena_t *arena, FILE *stream)
Reads the contents of a file from stream into a string.
Definition file.c:37
string * read_file_bytes(arena_t *arena, const string *path, const u64 bytes)
Read bytes from a file path to string.
Definition file.c:78
u64 file_size_stream(FILE *stream)
Gets the size of a file from a file stream.
Definition file.c:12
u64 file_size(const string *path)
Gets the size of a file at path.
Definition file.c:23
u64 write_to_file(const string *path, const string *contents)
Write contents to file path.
Definition file.c:104
string * read_file_from_stream_bytes(arena_t *arena, FILE *stream, const u64 bytes)
Read bytes from file stream to string.
Definition file.c:64
u64 write_to_file_stream(FILE *stream, const string *contents)
Write contents to file stream.
Definition file.c:93
string * read_file(arena_t *arena, const string *path)
Reads the contents of a file at path into a string.
Definition file.c:50
u64 write_to_file_bytes(const string *path, const string *contents, const u64 bytes)
Write bytes from contents to a file at path.
Definition file.c:132
u64 write_to_file_stream_bytes(FILE *stream, const string *contents, const u64 bytes)
Write bytes from contents to stream.
Definition file.c:119
An atomic arena.
Definition arena.h:45