|
| 1 | +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 2 | + |
| 3 | +#pragma once |
| 4 | + |
| 5 | +#ifndef VERSION |
| 6 | +#define VERSION "SNAPSHOT" |
| 7 | +#endif |
| 8 | + |
| 9 | +#define _DEFAULT_SOURCE |
| 10 | +#define _FILE_OFFSET_BITS 64 |
| 11 | + |
| 12 | +#include <features.h> |
| 13 | + |
| 14 | +#include <stdbool.h> |
| 15 | +#include <stdint.h> |
| 16 | +#include <stdio.h> |
| 17 | + |
| 18 | + |
| 19 | +// messaging and logging |
| 20 | +void message(const char *text); |
| 21 | + |
| 22 | +enum { LOG_ERR = 0, LOG_WARNING = 1, LOG_INFO = 2 }; |
| 23 | +void userlog(int priority, const char* format, ...); |
| 24 | + |
| 25 | +#define CHECK_NULL(p, r) if ((p) == NULL) { userlog(LOG_ERR, "out of memory"); return r; } |
| 26 | + |
| 27 | + |
| 28 | +// variable-length array |
| 29 | +typedef struct array_str array; |
| 30 | + |
| 31 | +array* array_create(int initial_capacity); |
| 32 | +int array_size(array* a); |
| 33 | +void* array_push(array* a, void* element); |
| 34 | +void* array_pop(array* a); |
| 35 | +void array_put(array* a, int index, void* element); |
| 36 | +void* array_get(array* a, int index); |
| 37 | +void array_delete(array* a); |
| 38 | +void array_delete_vs_data(array* a); |
| 39 | +void array_delete_data(array* a); |
| 40 | + |
| 41 | + |
| 42 | +// poor man's hash table |
| 43 | +typedef struct table_str table; |
| 44 | + |
| 45 | +table* table_create(int capacity); |
| 46 | +void* table_put(table* t, int key, void* value); |
| 47 | +void* table_get(table* t, int key); |
| 48 | +void table_delete(table* t); |
| 49 | + |
| 50 | + |
| 51 | +// inotify subsystem |
| 52 | +enum { |
| 53 | + ERR_IGNORE = -1, |
| 54 | + ERR_CONTINUE = -2, |
| 55 | + ERR_ABORT = -3, |
| 56 | + ERR_MISSING = -4 |
| 57 | +}; |
| 58 | + |
| 59 | +bool init_inotify(void); |
| 60 | + |
| 61 | +void set_inotify_callback(void (*callback)(const char *, uint32_t)); |
| 62 | +int get_inotify_fd(void); |
| 63 | +int watch(const char* root, array* mounts); |
| 64 | +void unwatch(int id, char* path, unsigned int path_len); |
| 65 | +bool process_inotify_input(void); |
| 66 | +void close_inotify(void); |
| 67 | + |
| 68 | + |
| 69 | +// reads one line from stream, trims trailing carriage return if any |
| 70 | +// returns pointer to the internal buffer (will be overwritten on next call) |
| 71 | +char* read_line(FILE* stream); |
| 72 | + |
| 73 | + |
| 74 | +// path comparison |
| 75 | +bool is_parent_path(const char* parent_path, const char* child_path); |
0 commit comments