/[osn-commons]/trunk/uar/uar.h
ViewVC logotype

Contents of /trunk/uar/uar.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations)
Wed Aug 7 18:57:45 2024 UTC (7 months, 3 weeks ago) by rakinar2
File MIME type: text/x-c
File size: 3572 byte(s)
refactor(uar): better I/O strategies to decrease memory usage
1 #ifndef UAR_UAR_H
2 #define UAR_UAR_H
3
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <sys/stat.h>
7 #include <sys/types.h>
8
9 struct uar_archive;
10 struct uar_file;
11
12 enum uar_error
13 {
14 UAR_SUCCESS,
15 UAR_INVALID_MAGIC,
16 UAR_INVALID_FILE,
17 UAR_IO_ERROR,
18 UAR_OUT_OF_MEMORY,
19 UAR_INVALID_ARGUMENT,
20 UAR_INVALID_OPERATION,
21 UAR_INVALID_PATH,
22 UAR_SYSTEM_ERROR,
23 UAR_SYSCALL_ERROR,
24 };
25
26 enum uar_file_type
27 {
28 UF_FILE,
29 UF_DIR,
30 UF_LINK
31 };
32
33 typedef bool (*uar_callback_t) (struct uar_archive *uar, struct uar_file *file,
34 const char *uar_name, const char *fs_name);
35
36 struct uar_archive *uar_create (void);
37 struct uar_archive *uar_open (const char *filename);
38 struct uar_archive *uar_create_stream (void);
39 void uar_close (struct uar_archive *uar);
40
41 struct uar_file *uar_stream_add_file (struct uar_archive *uar,
42 const char *uar_filename,
43 const char *fs_filename,
44 struct stat *stinfo);
45 bool uar_stream_write (struct uar_archive *uar, const char *filename);
46
47 bool uar_has_error (const struct uar_archive *restrict uar);
48 const char *uar_strerror (const struct uar_archive *restrict uar);
49 uint64_t uar_get_file_count (const struct uar_archive *restrict uar);
50
51 struct uar_file *uar_add_file (struct uar_archive *restrict uar,
52 const char *name, const char *path,
53 struct stat *stinfo);
54 struct uar_file *
55 uar_add_dir (struct uar_archive *uar, const char *name, const char *path,
56 bool (*callback) (struct uar_file *file, const char *fullname,
57 const char *fullpath));
58 bool uar_extract (struct uar_archive *uar, const char *cwd,
59 bool (*callback) (struct uar_file *file));
60 bool uar_write (struct uar_archive *uar, const char *filename);
61 bool uar_iterate (struct uar_archive *uar,
62 bool (*callback) (struct uar_file *file, void *data),
63 void *data);
64
65 struct uar_file *uar_file_create (const char *name, uint64_t namelen,
66 uint64_t size, uint32_t offset);
67
68 bool uar_add_file_entry (struct uar_archive *restrict uar,
69 struct uar_file *file);
70
71 void uar_file_destroy (struct uar_file *file);
72
73 struct uar_file *uar_stream_add_entry (struct uar_archive *uar,
74 const char *uar_name,
75 const char *fs_name, struct stat *stinfo,
76 uar_callback_t callback);
77 struct uar_file *uar_stream_add_dir (struct uar_archive *uar,
78 const char *uar_dirname,
79 const char *fs_dirname,
80 struct stat *stinfo,
81 uar_callback_t callback);
82
83 const char *uar_file_get_name (const struct uar_file *file);
84 enum uar_file_type uar_file_get_type (const struct uar_file *file);
85 uint64_t uar_file_get_size (const struct uar_file *file);
86 mode_t uar_file_get_mode (const struct uar_file *file);
87 void uar_file_set_mode (struct uar_file *file, mode_t mode);
88 uint64_t uar_file_get_namelen (const struct uar_file *file);
89 time_t uar_file_get_mtime (const struct uar_file *file);
90 const char *uar_get_error_file (const struct uar_archive *uar);
91
92 #ifdef UAR_PRINT_VERBOSE_IMPL_INFO
93 void uar_debug_print (const struct uar_archive *uar, bool print_file_contents);
94 #endif
95
96 #endif /* UAR_UAR_H */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26