Skip to content

Commit

Permalink
Merge pull request #25 from dmercer-google/headers-for-cpp
Browse files Browse the repository at this point in the history
Making utils headers available to c++
  • Loading branch information
sidcha committed Dec 15, 2023
2 parents cd90eef + c985f62 commit fb3202b
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/utils/arg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

#define AP_HELP_SPACING 25

#define AP_OPT_NOFLAG 0x00000000
Expand Down Expand Up @@ -56,4 +60,8 @@ void ap_init(const char *app_name, const char *app_desc);
int ap_parse(int argc, char *argv[], struct ap_option *ap_opts, void *data);
void ap_print_help(struct ap_option *ap_opts, int exit_code);

#ifdef __cplusplus
}
#endif

#endif /* _UTIL_ARG_PARSER_H_ */
8 changes: 8 additions & 0 deletions include/utils/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <stdio.h>
#include <utils/utils.h>

#ifdef __cplusplus
extern "C" {
#endif

#define __ASSERT_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)

#define __ASSERT_LOC(test) \
Expand All @@ -29,4 +33,8 @@
} \
} while (0)

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_ERROR_H_ */
8 changes: 8 additions & 0 deletions include/utils/bus_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <pthread.h>
#include <utils/workqueue.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
int fd;
int max_clients;
Expand All @@ -22,4 +26,8 @@ typedef struct {
int bus_server_start(bus_server_t *s, int max_clients, const char *path);
void bus_server_stop(bus_server_t *s);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_BUS_SERVER_H_ */
8 changes: 8 additions & 0 deletions include/utils/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
# if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) || \
Expand Down Expand Up @@ -101,4 +105,8 @@

#endif

#ifdef __cplusplus
}
#endif

#endif /* __BYTEORDER_H_ */
8 changes: 8 additions & 0 deletions include/utils/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include <utils/hashmap.h>

#ifdef __cplusplus
extern "C" {
#endif

enum channel_errors {
CHANNEL_ERR_NONE,
CHANNEL_ERR_ALREADY_OPEN,
Expand Down Expand Up @@ -86,4 +90,8 @@ int channel_close(struct channel_manager *ctx, const char *device);

void channel_manager_teardown(struct channel_manager *ctx);

#ifdef __cplusplus
}
#endif

#endif /* _CHANNEL_H_ */
8 changes: 8 additions & 0 deletions include/utils/circbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/** --- Internal methods and structures. DON'T USE --------------------------- */
typedef struct {
void * const buffer;
Expand Down Expand Up @@ -117,4 +121,8 @@ int __circbuf_free_space(circbuf_t *circbuf);
*/
#define CIRCBUF_FS(buf) __circbuf_free_space(&buf)

#ifdef __cplusplus
}
#endif

#endif /* _UTIL_CIRCBUF_H_ */
8 changes: 8 additions & 0 deletions include/utils/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

uint32_t compute_crc32(uint32_t seed, const uint8_t *buffer, size_t length);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_CRC32_H_ */
8 changes: 8 additions & 0 deletions include/utils/disjoint_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef _UTIL_DISJOINT_SET_H_
#define _UTIL_DISJOINT_SET_H_

#ifdef __cplusplus
extern "C" {
#endif

#define DISJOINT_SET_MAX 128

struct disjoint_set {
Expand All @@ -20,4 +24,8 @@ int disjoint_set_find(struct disjoint_set *set, int a);
void disjoint_set_union(struct disjoint_set *set, int a, int b);
int disjoint_set_num_roots(struct disjoint_set *set);

#ifdef __cplusplus
}
#endif

#endif /* _UTIL_DISJOINT_SET_H_ */
8 changes: 8 additions & 0 deletions include/utils/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#ifndef _UTILS_EVENTS_H_
#define _UTILS_EVENTS_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
int rfd;
int wfd;
Expand All @@ -21,4 +25,8 @@ void event_cleanup(event_t *e);
bool event_set(event_t *e);
bool event_is_set(event_t *e);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_EVENTS_H_ */
8 changes: 8 additions & 0 deletions include/utils/fdutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
#include <unistd.h>
#include <sys/fcntl.h>

#ifdef __cplusplus
extern "C" {
#endif

int fcntl_setfl(int fd, int flag);

ssize_t read_loop(int fd, void *buf, size_t max_len);
ssize_t write_loop(int fd, const void *buf, size_t len);
int flush_fd(int fd);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_FDUTILS_H_ */
8 changes: 8 additions & 0 deletions include/utils/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

int read_binary_file(const char *path, uint8_t **buf, size_t *size);
int write_binary_file(const char *path, uint8_t *buf, size_t size);

Expand All @@ -27,4 +31,8 @@ void fs_path_walk_free(char **files);
size_t file_size(FILE *fp);
bool dir_exists(const char *path);

#ifdef __cplusplus
}
#endif

#endif /* _UTIL_FILE_H_ */
8 changes: 8 additions & 0 deletions include/utils/filo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
void *buffer;
size_t top;
Expand Down Expand Up @@ -179,4 +183,8 @@ void filo_free(filo_t *pfilo);



#ifdef __cplusplus
}
#endif

#endif /* _UTILS_FILO_H_ */
8 changes: 8 additions & 0 deletions include/utils/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct hash_map_item_s hash_map_item_t;
typedef uint32_t hash_t;

Expand Down Expand Up @@ -50,4 +54,8 @@ int hash_map_it_next(hash_map_iterator_t *it, char **key, void **val);
hash_map_it_init(&it, map); \
while (hash_map_it_next(&it, key_ref, (void **)val_ref) == 0)

#ifdef __cplusplus
}
#endif

#endif /* _HASHMAP_H_ */
8 changes: 8 additions & 0 deletions include/utils/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct node_s node_t;

struct node_s {
Expand Down Expand Up @@ -61,4 +65,8 @@ int slist_popleft(slist_t *list, snode_t **node);
int slist_remove_node(slist_t *list, snode_t *node);
void slist_insert_node(slist_t *list, snode_t *after, snode_t *new);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_LIST_H_ */
8 changes: 8 additions & 0 deletions include/utils/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <stdio.h>
#include <utils/utils.h>

#ifdef __cplusplus
extern "C" {
#endif

#define LOGGER_NAME_MAXLEN 16

/**
Expand Down Expand Up @@ -85,4 +89,8 @@ void logger_set_name(logger_t *ctx, const char *name);

#define LOG_PRINT(...) __logger_log(NULL, LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif /* _LOGGER_H_ */
8 changes: 8 additions & 0 deletions include/utils/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Check p to be not NULL before calling safe_free()
*
Expand All @@ -28,4 +32,8 @@ void *safe_realloc(void *data, size_t size);
void *safe_strdup(const char *s);
void *safe_realloc_zero(void *data, size_t old_size, size_t new_size);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_MEMORY_H_ */
8 changes: 8 additions & 0 deletions include/utils/procutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef _UTIL_PROCUTILS_H_
#define _UTIL_PROCUTILS_H_

#ifdef __cplusplus
extern "C" {
#endif

/*
* read_pid() - Reads PID from `file`. The file's content must just be
* be PID number, as written by a call to write_pid(). On success, copies
Expand Down Expand Up @@ -91,4 +95,8 @@ unsigned any_pid_of(const char* exe_name);
char *parse_proc_cmdline(unsigned pid, int pos);


#ifdef __cplusplus
}
#endif

#endif /* _UTIL_PROCUTILS_H_ */
8 changes: 8 additions & 0 deletions include/utils/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include <utils/list.h>

#ifdef __cplusplus
extern "C" {
#endif

#define queue_node_t node_t

typedef struct {
Expand All @@ -22,4 +26,8 @@ int queue_dequeue(queue_t *queue, queue_node_t **node);
int queue_peek_last(queue_t *queue, queue_node_t **node);
int queue_peek_first(queue_t *queue, queue_node_t **node);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_QUEUE_H_ */
8 changes: 8 additions & 0 deletions include/utils/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Get the secure random bytes from the systems
*
Expand All @@ -20,4 +24,8 @@
*/
bool get_random_bytes(uint8_t *out, size_t len);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions include/utils/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include <utils/utils.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
uint8_t *blob;
size_t size;
Expand Down Expand Up @@ -49,4 +53,8 @@ int slab_alloc(slab_t *slab, void **block);
*/
int slab_free(slab_t *slab, void *block);

#ifdef __cplusplus
}
#endif

#endif /* _UTILS_SLAB_H_ */
Loading

0 comments on commit fb3202b

Please sign in to comment.