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#include <stdio.h>
5#include <sys/stat.h>
6
7//
8//
9//
10
11#include <htils/arena.h>
12#include <htils/basictypes.h>
13#include <htils/string.h>
14
17#if defined(_WIN32)
18#include <windows.h>
19
20#define fileno _fileno
21#define stat _stat64
22#define fstat _fstati64
23#endif
24
25//
26//
27//
28
58u64 file_size_stream(FILE *stream);
59
73u64 file_size(const string *path);
74
75//
76//
77//
78
98string *read_file_from_stream(arena_t *arena, FILE *stream);
99
116string *read_file(arena_t *arena, const string *path);
117
118//
119//
120//
121
142string *read_file_from_stream_bytes(arena_t *arena, FILE *stream,
143 const u64 bytes);
144
161string *read_file_bytes(arena_t *arena, const string *path, const u64 bytes);
162
163//
164//
165//
166
187u64 write_to_file_stream(FILE *stream, const string *contents);
188
204u64 write_to_file(const string *path, const string *contents);
205
207// Write to file by bytes
208//
209
232u64 write_to_file_stream_bytes(FILE *stream, const string *contents,
233 const u64 bytes);
234
250u64 write_to_file_bytes(const string *path, const string *contents,
251 const u64 bytes);
252
253//
254//
255//
256
257#endif // !HTILS_FILE_H
uint64_t u64
Definition basictypes.h:18
string * read_file_from_stream(arena_t *arena, FILE *stream)
Reads the contents of a file from stream into a string.
Definition file.c:46
string * read_file_bytes(arena_t *arena, const string *path, const u64 bytes)
Read bytes from a file path to string.
Definition file.c:91
u64 file_size_stream(FILE *stream)
Gets the size of a file from a file stream.
Definition file.c:17
u64 file_size(const string *path)
Gets the size of a file at path.
Definition file.c:28
u64 write_to_file(const string *path, const string *contents)
Write contents to file path.
Definition file.c:121
string * read_file_from_stream_bytes(arena_t *arena, FILE *stream, const u64 bytes)
Read bytes from file stream to string.
Definition file.c:77
u64 write_to_file_stream(FILE *stream, const string *contents)
Write contents to file stream.
Definition file.c:110
string * read_file(arena_t *arena, const string *path)
Reads the contents of a file at path into a string.
Definition file.c:59
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:153
u64 write_to_file_stream_bytes(FILE *stream, const string *contents, const u64 bytes)
Write bytes from contents to stream.
Definition file.c:140
An arena.
Definition arena.h:33