Upgrade libutils to C++

This commit is contained in:
topjohnwu
2018-11-03 03:06:01 -04:00
parent ef6677f43d
commit 6339ba6bfb
15 changed files with 200 additions and 304 deletions

View File

@@ -1,43 +0,0 @@
/* list.h - Double link list implementation
*/
#ifndef _LIST_H_
#define _LIST_H_
#include <stddef.h>
struct list_head {
struct list_head *next;
struct list_head *prev;
};
void init_list_head(struct list_head *head);
void list_insert(struct list_head *pos, struct list_head *node);
void list_insert_end(struct list_head *head, struct list_head *node);
struct list_head *list_pop(struct list_head *pos);
struct list_head *list_pop_end(struct list_head *head);
#define list_entry(pos, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (pos); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#define list_for_each(ptr, head, type, member) \
ptr = list_entry((head)->next, type, member); \
for (struct list_head *__ = (head)->next; __ != (head); __ = __->next, ptr = list_entry(__, type, member))
#define list_for_each_r(ptr, head, type, member) \
ptr = list_entry((head)->prev, type, member); \
for (struct list_head *__ = (head)->prev; __ != (head); __ = __->prev, ptr = list_entry(__, type, member))
#define list_destory(head, type, member, func) ({ \
struct list_head *node = head->next; \
while(node != head) { \
node = node->next; \
if (func) func(list_entry(node->prev, line_list, pos)); \
free(list_entry(node->prev, line_list, pos)); \
} \
head->next = head; \
head->prev = head; \
})
#endif

View File

@@ -1,6 +1,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern void (*freecon)(char * con);
extern int (*setcon)(const char * con);
extern int (*getfilecon)(const char *path, char ** con);
@@ -10,3 +14,7 @@ extern int (*lsetfilecon)(const char *path, const char * con);
void dload_selinux();
void restorecon();
#ifdef __cplusplus
}
#endif

View File

@@ -12,6 +12,9 @@
#include <sys/stat.h>
#ifdef __cplusplus
// C++ only
#include "array.h"
int file_to_array(const char* filename, Array<char *> &arr);
extern "C" {
#endif
@@ -92,7 +95,6 @@ int exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *a
int exec_command_sync(char *const argv0, ...);
int switch_mnt_ns(int pid);
int fork_dont_care();
void wait_till_exists(const char *target);
void gen_rand_str(char *buf, int len);
int strend(const char *s1, const char *s2);

View File

@@ -1,6 +0,0 @@
#pragma once
#include "utils.h"
#include "array.h"
int file_to_array(const char* filename, Array<char *> &arr);