feat: add simple inotify prototype
This commit is contained in:
25
include/cli.h
Normal file
25
include/cli.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef SCI_CLI_H
|
||||
#define SCI_CLI_H
|
||||
#include <stdio.h>
|
||||
#include "optional.h"
|
||||
|
||||
struct cli_options {
|
||||
optional_str file;
|
||||
int verbosity;
|
||||
bool help;
|
||||
bool version;
|
||||
};
|
||||
|
||||
// Construct a new cli_options struct instance.
|
||||
struct cli_options new_options();
|
||||
|
||||
// Delete a cli_options struct instance.
|
||||
void free_options(struct cli_options v);
|
||||
|
||||
// Print the help message.
|
||||
void print_help(FILE * out, char* prog_name);
|
||||
|
||||
// Parse the command line arguments and give a new cli_options struct instance.
|
||||
struct cli_options parse(int argc, char** argv);
|
||||
|
||||
#endif
|
11
include/notify.h
Normal file
11
include/notify.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef SCI_NOTIFY_H
|
||||
#define SCI_NOTIFY_H
|
||||
#include <sys/inotify.h>
|
||||
|
||||
typedef void(*notify_callback)(struct inotify_event* const);
|
||||
|
||||
// Start listening for changes to the provided file.
|
||||
// Note that the `struct inotify_event*` provided is a managed pointer.
|
||||
void listen_for_changes(const char* filename, notify_callback callback);
|
||||
|
||||
#endif
|
11
include/optional.h
Normal file
11
include/optional.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef SCI_OPTIONAL_H
|
||||
#define SCI_OPTIONAL_H
|
||||
#include <stdbool.h>
|
||||
|
||||
#define optional_type(type) struct { bool has_value; type value; }
|
||||
typedef optional_type(int) optional_int;
|
||||
typedef optional_type(float) optional_float;
|
||||
typedef optional_type(char*) optional_str;
|
||||
typedef optional_type(const char*) optional_cstr;
|
||||
|
||||
#endif
|
17
include/util.h
Normal file
17
include/util.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef SCI_UTIL_H
|
||||
#define SCI_UTIL_H
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ASSERT_SYSCALL_SUCCESS(fd) \
|
||||
do { \
|
||||
if ((fd) == -1) { \
|
||||
fprintf(stderr, "Assertion failed: %s, errno: %d, error: %s\n", #fd, errno, strerror(errno)); \
|
||||
assert(fd != -1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user