1 #ifndef NM_CORE_H_ 2 #define NM_CORE_H_ 3 4 #include <stdio.h> 5 #include <ctype.h> 6 #include <locale.h> 7 #include <signal.h> 8 #include <stdlib.h> 9 #include <stdarg.h> 10 #include <string.h> 11 #include <unistd.h> 12 #include <stdbool.h> 13 #include <libintl.h> 14 #include <fcntl.h> 15 #include <inttypes.h> 16 #include <regex.h> 17 #include <getopt.h> 18 #include <limits.h> 19 20 #include <pwd.h> 21 #include <errno.h> 22 23 #include <sys/stat.h> 24 #include <sys/types.h> 25 #include <sys/mman.h> 26 27 #include <nm_cfg_file.h> 28 #include <nm_database.h> 29 30 #define NM_PROGNAME "nemu" 31 32 #ifndef NM_VERSION 33 #define NM_VERSION "v3.0.0" 34 #endif 35 36 #define nm_min(a, b) \ 37 __extension__({ \ 38 __typeof__ (a) _a = (a); \ 39 __typeof__ (b) _b = (b); \ 40 _a < _b ? _a : _b; \ 41 }) 42 #define nm_max(a, b) \ 43 __extension__({ \ 44 __typeof__ (a) _a = (a); \ 45 __typeof__ (b) _b = (b); \ 46 _a > _b ? _a : _b; \ 47 }) 48 #define nm_arr_len(p) (sizeof(p) / sizeof((p)[0])) 49 50 #define NM_UNUSED __attribute__((__unused__)) 51 52 static const int NM_OK = 0; 53 static const int NM_ERR = -1; 54 55 static const bool NM_TRUE = true; 56 static const bool NM_FALSE = false; 57 58 static const char NM_ENABLE[] = "1"; 59 static const char NM_DISABLE[] = "0"; 60 61 static const char NM_DEFAULT_NETDRV[] = "virtio-net-pci"; 62 static const char NM_DEFAULT_DRVINT[] = "virtio"; 63 static const char NM_DEFAULT_USBVER[] = "XHCI"; 64 static const char NM_VM_PID_FILE[] = "qemu.pid"; 65 static const char NM_VM_QMP_FILE[] = "qmp.sock"; 66 static const char NM_DEFAULT_DISPLAY[] = "qxl"; 67 static const char NM_MQ_PATH[] = "/nemu-qmp"; 68 _(const char * str)69static inline char * __attribute__((format_arg (1))) _(const char *str) 70 { 71 return gettext(str); 72 } nm_init_core()73static inline void nm_init_core() 74 { 75 nm_cfg_init(); 76 nm_db_init(); 77 } nm_exit_core()78static inline void __attribute__((noreturn)) nm_exit_core() 79 { 80 if (nm_db_in_transaction()) 81 nm_db_rollback(); 82 83 nm_db_close(); 84 nm_cfg_free(); 85 exit(NM_OK); 86 } compar_uint32_t(const void * a,const void * b)87static inline int compar_uint32_t(const void *a, const void *b) 88 { 89 const uint32_t _a = *(const uint32_t*)a; 90 const uint32_t _b = *(const uint32_t*)b; 91 if (_a != _b) 92 return _a < _b ? -1 : 1; 93 94 return 0; 95 } 96 97 #endif /* NM_CORE_H_ */ 98 /* vim:set ts=4 sw=4: */ 99