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
6//
7//
8//
9
10#include <htils/arena.h>
11#include <htils/basictypes.h>
12#include <htils/string.h>
13
16#if defined(_WIN32)
17#include <shellapi.h>
18#include <windows.h>
19
20#define fseek64 _fseeki64
21#define ftell64 _ftelli64
22#elif defined(__linux__)
23#include <sys/stat.h>
24#include <unistd.h>
25
26#define fseek64 fseeko
27#define ftell64 ftello
28#else
29#error "Unsupported platform."
30#endif
31
32//
33//
34//
35
62u64 file_size_stream(FILE *stream);
63
77u64 file_size(const string *path);
78
79//
80//
81//
82
102string *read_file_from_stream(arena_t *arena, FILE *stream);
103
120string *read_file(arena_t *arena, const string *path);
121
122//
123//
124//
125
146string *read_file_from_stream_bytes(arena_t *arena, FILE *stream,
147 const u64 bytes);
148
165string *read_file_bytes(arena_t *arena, const string *path, const u64 bytes);
166
167//
168//
169//
170
191u64 write_to_file_stream(FILE *stream, const string *contents);
192
208u64 write_to_file(const string *path, const string *contents);
209
211// Write to file by bytes
212//
213
236u64 write_to_file_stream_bytes(FILE *stream, const string *contents,
237 const u64 bytes);
238
254u64 write_to_file_bytes(const string *path, const string *contents,
255 const u64 bytes);
256
257//
258//
259//
260
261#endif // !HTILS_FILE_H
uint64_t u64
Definition basictypes.h:17
string * read_file_from_stream(arena_t *arena, FILE *stream)
Reads the contents of a file from stream into a string.
Definition file.c:48
string * read_file_bytes(arena_t *arena, const string *path, const u64 bytes)
Read bytes from a file path to string.
Definition file.c:93
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:31
u64 write_to_file(const string *path, const string *contents)
Write contents to file path.
Definition file.c:122
string * read_file_from_stream_bytes(arena_t *arena, FILE *stream, const u64 bytes)
Read bytes from file stream to string.
Definition file.c:79
u64 write_to_file_stream(FILE *stream, const string *contents)
Write contents to file stream.
Definition file.c:111
string * read_file(arena_t *arena, const string *path)
Reads the contents of a file at path into a string.
Definition file.c:62
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:26