blob: 91840537450eac258997267ce9eff26ca03a1236 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#ifndef AMALGAM_FILE_H
#define AMALGAM_FILE_H
#include "misc.h"
#include "types.h"
#include "buffer_view.h"
#include "buffer.h"
/* Return bool_true if you want to continue scanning, otherwise return bool_false */
typedef bool (*scan_dir_callback_func)(const char *filepath, int filepath_length, void *userdata);
typedef struct {
const char *file_data;
usize file_size;
int fd;
} MappedFile;
typedef enum {
MAPPED_FILE_READ,
MAPPED_FILE_WRITE,
MAPPED_FILE_READ_WRITE
} MappedFileMode;
/* Hidden files (files starting with a dot) are skipped */
/*
TODO: Remove the 3 following functions as they are not used.
They should be implemented in amalgam instead.
*/
#if 0
CHECK_RESULT int scan_dir_recursive(const char *dir_path, scan_dir_callback_func callback_func, void *userdata);
CHECK_RESULT int mapped_file_init(MappedFile *self, const char *filepath, MappedFileMode file_mode);
CHECK_RESULT int mapped_file_deinit(MappedFile *self);
#endif
CHECK_RESULT int read_whole_file(const char *filepath, Buffer *result);
/* @result_path will be allocated with am_malloc, should be deallocated with am_free */
CHECK_RESULT int file_get_canonical_path(const char *filepath, char **result_path, usize *result_path_size);
BufferView file_get_parent_directory(BufferView filepath);
BufferView file_get_name(BufferView filepath);
#endif
|