summaryrefslogtreecommitdiffstats
path: root/backend/fileaccess.h
blob: f5e69d7308363d4f1381ad89408bb4dd295d2e8c (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
43
44
45
46
47
48
49
50
51
#ifndef BACKEND_FILEACCESS_H_
#define BACKEND_FILEACCESS_H_

#include "list.h"

#include <stdarg.h>
#include <fcntl.h>
#include <stdio.h>
#include <dirent.h>


struct fileaccess {
	int fd;
	FILE *stream;
};

void file_close(struct fileaccess *fa);
struct fileaccess * file_open(int flags, const char *path_fmt, ...);
struct fileaccess * sysfs_file_open(int flags, const char *path_fmt, ...);
struct fileaccess * procfs_file_open(int flags, const char *path_fmt, ...);

int file_read_buf(struct fileaccess *fa, char *buf, size_t size);
int file_read_string(struct fileaccess *fa, char *buf, size_t size);
int file_read_int(struct fileaccess *fa, int *value, int base);
int file_write_int(struct fileaccess *fa, int value, int base);
int file_read_bool(struct fileaccess *fa, int *value);
int file_write_bool(struct fileaccess *fa, int value);

struct text_line {
	char *text;
	struct list_head list;
};

int file_read_text_lines(struct fileaccess *fa, struct list_head *lines_list,
			 int strip_whitespace);
void text_line_free(struct text_line *tl);
void text_lines_free(struct list_head *lines_list);

struct dir_entry {
	char *name;
	unsigned int type; /* DT_... */
	struct list_head list;
};

int list_directory(struct list_head *dir_entries, const char *path_fmt, ...);
int list_sysfs_directory(struct list_head *dir_entries, const char *path_fmt, ...);
int list_procfs_directory(struct list_head *dir_entries, const char *path_fmt, ...);
void dir_entry_free(struct dir_entry *dir_entry);
void dir_entries_free(struct list_head *dir_entries);

#endif /* BACKEND_FILEACCESS_H_ */
bues.ch cgit interface