1 #ifndef NM_UTILS_H_
2 #define NM_UTILS_H_
3 
4 #include <nm_string.h>
5 #include <nm_vector.h>
6 
7 typedef struct {
8     const nm_str_t *name;
9     int fd;
10     off_t size;
11     void *mp;
12 } nm_file_map_t;
13 
14 typedef struct {
15     size_t smp;
16     size_t sockets;
17     size_t cores;
18     size_t threads;
19 } nm_cpu_t;
20 
21 #define NM_INIT_FILE (nm_file_map_t) { NULL, -1, 0, NULL }
22 #define NM_INIT_CPU (nm_cpu_t) { 0, 0, 0, 0 }
23 
24 void *nm_alloc(size_t size);
25 void *nm_calloc(size_t nmemb, size_t size);
26 void *nm_realloc(void *p, size_t size);
27 void nm_map_file(nm_file_map_t *file);
28 void nm_copy_file(const nm_str_t *src, const nm_str_t *dst);
29 void nm_unmap_file(const nm_file_map_t *file);
30 /* Execute process. Read stdout if answer is not NULL */
31 int nm_spawn_process(const nm_vect_t *argv, nm_str_t *answer);
32 
33 void nm_bug(const char *fmt, ...)
34     __attribute__ ((format(printf, 1, 2)))
35     __attribute__((noreturn));
36 
37 void nm_debug(const char *fmt, ...)
38     __attribute__ ((format(printf, 1, 2)));
39 
40 void nm_cmd_str(nm_str_t *str, const nm_vect_t *argv);
41 void nm_parse_smp(nm_cpu_t *cpu, const char *src);
42 
43 void nm_exit(int status)
44     __attribute__((noreturn));
45 
46 int nm_mkdir_parent(const nm_str_t *path, mode_t mode);
47 
48 const char *nm_nemu_path();
49 
50 /*
51  * get date and time, format:
52  *
53  * %Y - year
54  * %m - month
55  * %d - day of the month
56  * %H - hours
57  * %M - minutes
58  * %S - seconds
59  * %% - '%'
60  */
61 void nm_get_time(nm_str_t *res, const char *fmt);
62 void nm_gen_rand_str(nm_str_t *res, size_t len);
63 void nm_gen_uid(nm_str_t *res);
64 
65 #endif /* NM_UTILS_H_ */
66 /* vim:set ts=4 sw=4: */
67