Change indentation to follow the updated standard.
Alot of mixed indentation. use 4 chars wide soft tabs.
This commit is contained in:
parent
9cc5420447
commit
f46ae1970b
51 changed files with 634 additions and 639 deletions
|
|
@ -96,4 +96,3 @@ Things to keep in mind when modify or write code
|
|||
------------------------------------------------
|
||||
|
||||
include and change the comment found in TEMPLATE file, at the top of the .c/.h file
|
||||
|
||||
|
|
|
|||
|
|
@ -48,4 +48,3 @@ database (String);;
|
|||
Database to use
|
||||
table (String);;
|
||||
Tablename to use
|
||||
|
||||
|
|
|
|||
|
|
@ -52,36 +52,36 @@ static int load_config(const char *file) {
|
|||
when in main loop is by signal */
|
||||
static void clean_exit(int excode) {
|
||||
|
||||
time_t t = time(NULL);
|
||||
time_t t = time(NULL);
|
||||
|
||||
notify_exit();
|
||||
notify_exit();
|
||||
|
||||
database_close();
|
||||
database_close();
|
||||
|
||||
iniparser_freedict(config);
|
||||
|
||||
printf("\nprocess exit at: %s", ctime(&t));
|
||||
exit(excode);
|
||||
printf("\nprocess exit at: %s", ctime(&t));
|
||||
exit(excode);
|
||||
}
|
||||
|
||||
/* Signal handler */
|
||||
static void sighandl(int sig) {
|
||||
|
||||
switch(sig) {
|
||||
/* normal exit signals */
|
||||
case SIGTERM :
|
||||
case SIGKILL :
|
||||
case SIGINT :
|
||||
clean_exit(EXIT_SUCCESS);
|
||||
/* segmentation violation, let user now */
|
||||
case SIGSEGV :
|
||||
fprintf(stderr, "SEGFAULT: o no he didn't\n");
|
||||
clean_exit(EXIT_FAILURE);
|
||||
case SIGUSR1 :
|
||||
case SIGUSR2 :
|
||||
printf("notify stat:\n");
|
||||
notify_stat();
|
||||
}
|
||||
switch(sig) {
|
||||
/* normal exit signals */
|
||||
case SIGTERM :
|
||||
case SIGKILL :
|
||||
case SIGINT :
|
||||
clean_exit(EXIT_SUCCESS);
|
||||
/* segmentation violation, let user now */
|
||||
case SIGSEGV :
|
||||
fprintf(stderr, "SEGFAULT: o no he didn't\n");
|
||||
clean_exit(EXIT_FAILURE);
|
||||
case SIGUSR1 :
|
||||
case SIGUSR2 :
|
||||
printf("notify stat:\n");
|
||||
notify_stat();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
96
src/event.c
96
src/event.c
|
|
@ -14,17 +14,17 @@
|
|||
#include "xalloc.h"
|
||||
|
||||
#define dealloc_data(ev) \
|
||||
if (ev->path) \
|
||||
xfree(ev->path); \
|
||||
if (ev->filename) \
|
||||
xfree(ev->filename)
|
||||
if (ev->path) \
|
||||
xfree(ev->path); \
|
||||
if (ev->filename) \
|
||||
xfree(ev->filename)
|
||||
|
||||
static void init_event(notify_event* ev) {
|
||||
|
||||
ev->filename = NULL;
|
||||
ev->path = NULL;
|
||||
ev->type = NOTIFY_UNKNOWN;
|
||||
ev->dir = 0;
|
||||
ev->filename = NULL;
|
||||
ev->path = NULL;
|
||||
ev->type = NOTIFY_UNKNOWN;
|
||||
ev->dir = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -32,11 +32,11 @@ static void init_event(notify_event* ev) {
|
|||
*/
|
||||
notify_event* notify_event_new() {
|
||||
|
||||
notify_event *ev = xmalloc(sizeof(notify_event));
|
||||
notify_event *ev = xmalloc(sizeof(notify_event));
|
||||
|
||||
init_event(ev);
|
||||
init_event(ev);
|
||||
|
||||
return ev;
|
||||
return ev;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -44,11 +44,11 @@ notify_event* notify_event_new() {
|
|||
*/
|
||||
void notify_event_del(notify_event *event) {
|
||||
|
||||
if (event == NULL)
|
||||
return;
|
||||
if (event == NULL)
|
||||
return;
|
||||
|
||||
dealloc_data(event);
|
||||
xfree(event);
|
||||
dealloc_data(event);
|
||||
xfree(event);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -56,11 +56,11 @@ void notify_event_del(notify_event *event) {
|
|||
*/
|
||||
void notify_event_clear(notify_event *event) {
|
||||
|
||||
if (event == NULL)
|
||||
return;
|
||||
if (event == NULL)
|
||||
return;
|
||||
|
||||
dealloc_data(event);
|
||||
init_event(event);
|
||||
dealloc_data(event);
|
||||
init_event(event);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -68,12 +68,12 @@ void notify_event_clear(notify_event *event) {
|
|||
*/
|
||||
void notify_event_set_path(notify_event *event, const char *path) {
|
||||
|
||||
if (event == NULL || path == NULL)
|
||||
return;
|
||||
if (event == NULL || path == NULL)
|
||||
return;
|
||||
|
||||
event->path = xrealloc(event->path, strlen(path)+1);
|
||||
event->path = xrealloc(event->path, strlen(path)+1);
|
||||
|
||||
memcpy(event->path, path, strlen(path)+1);
|
||||
memcpy(event->path, path, strlen(path)+1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -81,29 +81,29 @@ void notify_event_set_path(notify_event *event, const char *path) {
|
|||
*/
|
||||
void notify_event_set_filename(notify_event *event, const char *filename) {
|
||||
|
||||
if (event == NULL || filename == NULL)
|
||||
return;
|
||||
if (event == NULL || filename == NULL)
|
||||
return;
|
||||
|
||||
event->filename = xrealloc(event->filename, strlen(filename)+1);
|
||||
event->filename = xrealloc(event->filename, strlen(filename)+1);
|
||||
|
||||
memcpy(event->filename, filename, strlen(filename)+1);
|
||||
memcpy(event->filename, filename, strlen(filename)+1);
|
||||
}
|
||||
|
||||
/* set directory */
|
||||
void notify_event_set_dir(notify_event *event, uint8_t dir) {
|
||||
|
||||
if (event == NULL)
|
||||
return;
|
||||
if (event == NULL)
|
||||
return;
|
||||
|
||||
event->dir = dir;
|
||||
event->dir = dir;
|
||||
}
|
||||
|
||||
void notify_event_set_type(notify_event *event, uint8_t type) {
|
||||
|
||||
if (event == NULL)
|
||||
return;
|
||||
if (event == NULL)
|
||||
return;
|
||||
|
||||
event->type = type;
|
||||
event->type = type;
|
||||
}
|
||||
|
||||
const char* notify_event_typetostr(notify_event *event) {
|
||||
|
|
@ -111,19 +111,19 @@ const char* notify_event_typetostr(notify_event *event) {
|
|||
if (!event)
|
||||
return "(null)";
|
||||
|
||||
switch(event->type) {
|
||||
case NOTIFY_CREATE :
|
||||
return "CREATE";
|
||||
case NOTIFY_DELETE :
|
||||
return "DELETE";
|
||||
break;
|
||||
case NOTIFY_MOVE_FROM :
|
||||
return "MOVE_FROM";
|
||||
break;
|
||||
case NOTIFY_MOVE_TO :
|
||||
return "MOVE_TO";
|
||||
break;
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
switch(event->type) {
|
||||
case NOTIFY_CREATE :
|
||||
return "CREATE";
|
||||
case NOTIFY_DELETE :
|
||||
return "DELETE";
|
||||
break;
|
||||
case NOTIFY_MOVE_FROM :
|
||||
return "MOVE_FROM";
|
||||
break;
|
||||
case NOTIFY_MOVE_TO :
|
||||
return "MOVE_TO";
|
||||
break;
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
src/event.h
18
src/event.h
|
|
@ -15,17 +15,17 @@
|
|||
#include <stdint.h>
|
||||
|
||||
/* event types */
|
||||
#define NOTIFY_UNKNOWN (1 << 0)
|
||||
#define NOTIFY_CREATE (1 << 1)
|
||||
#define NOTIFY_DELETE (1 << 2)
|
||||
#define NOTIFY_MOVE_FROM (1 << 3)
|
||||
#define NOTIFY_MOVE_TO (1 << 4)
|
||||
#define NOTIFY_UNKNOWN (1 << 0)
|
||||
#define NOTIFY_CREATE (1 << 1)
|
||||
#define NOTIFY_DELETE (1 << 2)
|
||||
#define NOTIFY_MOVE_FROM (1 << 3)
|
||||
#define NOTIFY_MOVE_TO (1 << 4)
|
||||
|
||||
typedef struct {
|
||||
uint8_t type; /* type of event */
|
||||
uint8_t dir; /* non zero if event is triggered on a directory */
|
||||
char *path; /* path of the triggered event */
|
||||
char *filename; /* the filename event was triggered on */
|
||||
uint8_t type; /* type of event */
|
||||
uint8_t dir; /* non zero if event is triggered on a directory */
|
||||
char *path; /* path of the triggered event */
|
||||
char *filename; /* the filename event was triggered on */
|
||||
} notify_event;
|
||||
|
||||
notify_event* notify_event_new();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
(x)->fts_info == FTS_SLNONE)
|
||||
|
||||
struct __fscrawl {
|
||||
FTS *fts;
|
||||
FTS *fts;
|
||||
fs_entry ent;
|
||||
};
|
||||
|
||||
|
|
@ -60,12 +60,12 @@ static fs_entry* ftsentcpy(fs_entry *dest, FTSENT *src) {
|
|||
|
||||
fscrawl_t fsc_open(const char *path) {
|
||||
|
||||
struct __fscrawl *f;
|
||||
struct __fscrawl *f;
|
||||
char *npath;
|
||||
|
||||
f = malloc(sizeof(struct __fscrawl));
|
||||
if (!f)
|
||||
return NULL;
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
npath = path_normalize(path, NULL, 1);
|
||||
if (!npath)
|
||||
|
|
@ -82,7 +82,7 @@ fscrawl_t fsc_open(const char *path) {
|
|||
f->ent.base = NULL;
|
||||
f->ent.name = NULL;
|
||||
f->ent.dir = 0;
|
||||
return f;
|
||||
return f;
|
||||
free:
|
||||
if (f)
|
||||
free(f);
|
||||
|
|
@ -102,22 +102,22 @@ void fsc_close(fscrawl_t f) {
|
|||
|
||||
fs_entry* fsc_cpy(fs_entry *ent) {
|
||||
|
||||
void *ptr = malloc(sizeof(fs_entry));
|
||||
void *ptr = malloc(sizeof(fs_entry));
|
||||
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(ptr, ent, sizeof(fs_entry));
|
||||
memcpy(ptr, ent, sizeof(fs_entry));
|
||||
|
||||
return ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fs_entry* fsc_read(fscrawl_t f) {
|
||||
|
||||
FTSENT *ent;
|
||||
FTSENT *ent;
|
||||
|
||||
if (!f)
|
||||
return NULL;
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
for(;;) {
|
||||
ent = fts_read(f->fts);
|
||||
|
|
|
|||
|
|
@ -85,11 +85,11 @@ int inotify_backend_watch(const char *path) {
|
|||
|
||||
int wd = inotify_add_watch(fd, path, WATCH_MASK);
|
||||
|
||||
if (wd < 0) {
|
||||
if (wd < 0) {
|
||||
if (errno != EACCES && errno != ENOTDIR)
|
||||
logerrno(LOG_CRIT, "inotify_watch", errno);
|
||||
return -errno;
|
||||
}
|
||||
return -errno;
|
||||
}
|
||||
return wd;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,41 +16,41 @@
|
|||
|
||||
/* Structure describing an inotify event. */
|
||||
struct inotify_event {
|
||||
int wd; /* Watch descriptor. */
|
||||
uint32_t mask; /* Watch mask. */
|
||||
uint32_t cookie; /* Cookie to synchronize two events. */
|
||||
uint32_t len; /* Length (including NULs) of name. */
|
||||
char name __flexarr; /* Name. */
|
||||
int wd; /* Watch descriptor. */
|
||||
uint32_t mask; /* Watch mask. */
|
||||
uint32_t cookie; /* Cookie to synchronize two events. */
|
||||
uint32_t len; /* Length (including NULs) of name. */
|
||||
char name __flexarr; /* Name. */
|
||||
};
|
||||
|
||||
#define IN_EVENT_SIZE (sizeof(struct inotify_event) + 0x40)
|
||||
|
||||
/* Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH. */
|
||||
#define IN_ACCESS 0x00000001 /* File was accessed. */
|
||||
#define IN_MODIFY 0x00000002 /* File was modified. */
|
||||
#define IN_ATTRIB 0x00000004 /* Metadata changed. */
|
||||
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed. */
|
||||
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed. */
|
||||
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
|
||||
#define IN_OPEN 0x00000020 /* File was opened. */
|
||||
#define IN_MOVED_FROM 0x00000040 /* File was moved from X. */
|
||||
#define IN_MOVED_TO 0x00000080 /* File was moved to Y. */
|
||||
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
|
||||
#define IN_CREATE 0x00000100 /* Subfile was created. */
|
||||
#define IN_DELETE 0x00000200 /* Subfile was deleted. */
|
||||
#define IN_DELETE_SELF 0x00000400 /* Self was deleted. */
|
||||
#define IN_MOVE_SELF 0x00000800 /* Self was moved. */
|
||||
#define IN_ACCESS 0x00000001 /* File was accessed. */
|
||||
#define IN_MODIFY 0x00000002 /* File was modified. */
|
||||
#define IN_ATTRIB 0x00000004 /* Metadata changed. */
|
||||
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed. */
|
||||
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed. */
|
||||
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
|
||||
#define IN_OPEN 0x00000020 /* File was opened. */
|
||||
#define IN_MOVED_FROM 0x00000040 /* File was moved from X. */
|
||||
#define IN_MOVED_TO 0x00000080 /* File was moved to Y. */
|
||||
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
|
||||
#define IN_CREATE 0x00000100 /* Subfile was created. */
|
||||
#define IN_DELETE 0x00000200 /* Subfile was deleted. */
|
||||
#define IN_DELETE_SELF 0x00000400 /* Self was deleted. */
|
||||
#define IN_MOVE_SELF 0x00000800 /* Self was moved. */
|
||||
|
||||
/* Events sent by the kernel. */
|
||||
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted. */
|
||||
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed. */
|
||||
#define IN_IGNORED 0x00008000 /* File was ignored. */
|
||||
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted. */
|
||||
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed. */
|
||||
#define IN_IGNORED 0x00008000 /* File was ignored. */
|
||||
|
||||
/* Helper events. */
|
||||
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
|
||||
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
|
||||
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close. */
|
||||
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves. */
|
||||
|
||||
#define IN_ISDIR 0x40000000 /* Event occurred against dir. */
|
||||
#define IN_ISDIR 0x40000000 /* Event occurred against dir. */
|
||||
|
||||
int inotify_backend_init(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ static int unmap_wd(struct watch *watch) {
|
|||
int index;
|
||||
struct list s = { (void**)&watch, 1 }, *list;
|
||||
|
||||
list = rbtree_search(&tree_wd_paths, &s);
|
||||
list = rbtree_search(&tree_wd_paths, &s);
|
||||
if (list) {
|
||||
|
||||
index = list_indexof(list, watch);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#if defined(__i386__)
|
||||
# define __NR_inotify_init 291
|
||||
# define __NR_inotify_add_watch 292
|
||||
# define __NR_inotify_rm_watch 293
|
||||
# define __NR_inotify_init 291
|
||||
# define __NR_inotify_add_watch 292
|
||||
# define __NR_inotify_rm_watch 293
|
||||
#elif defined(__x86_64__)
|
||||
# define __NR_inotify_init 253
|
||||
# define __NR_inotify_add_watch 254
|
||||
# define __NR_inotify_rm_watch 255
|
||||
# define __NR_inotify_init 253
|
||||
# define __NR_inotify_add_watch 254
|
||||
# define __NR_inotify_rm_watch 255
|
||||
#elif defined(__alpha__)
|
||||
# define __NR_inotify_init 444
|
||||
# define __NR_inotify_add_watch 445
|
||||
|
|
@ -26,23 +26,23 @@
|
|||
# define __NR_inotify_add_watch 152
|
||||
# define __NR_inotify_rm_watch 156
|
||||
#elif defined (__ia64__)
|
||||
# define __NR_inotify_init 1277
|
||||
# define __NR_inotify_init 1277
|
||||
# define __NR_inotify_add_watch 1278
|
||||
# define __NR_inotify_rm_watch 1279
|
||||
#elif defined (__s390__) || defined (__s390x__)
|
||||
# define __NR_inotify_init 284
|
||||
# define __NR_inotify_init 284
|
||||
# define __NR_inotify_add_watch 285
|
||||
# define __NR_inotify_rm_watch 286
|
||||
#elif defined (__arm__)
|
||||
# define __NR_inotify_init 316
|
||||
# define __NR_inotify_init 316
|
||||
# define __NR_inotify_add_watch 317
|
||||
# define __NR_inotify_rm_watch 318
|
||||
#elif defined (__SH4__)
|
||||
# define __NR_inotify_init 290
|
||||
# define __NR_inotify_init 290
|
||||
# define __NR_inotify_add_watch 291
|
||||
# define __NR_inotify_rm_watch 292
|
||||
#elif defined (__SH5__)
|
||||
# define __NR_inotify_init 318
|
||||
# define __NR_inotify_init 318
|
||||
# define __NR_inotify_add_watch 319
|
||||
# define __NR_inotify_rm_watch 320
|
||||
#else
|
||||
|
|
@ -56,12 +56,12 @@ static inline int inotify_init(void) {
|
|||
|
||||
static inline int inotify_add_watch(int fd, const char *name, __u32 mask) {
|
||||
|
||||
return syscall(__NR_inotify_add_watch, fd, name, mask);
|
||||
return syscall(__NR_inotify_add_watch, fd, name, mask);
|
||||
}
|
||||
|
||||
static inline int inotify_rm_watch(int fd, __u32 wd) {
|
||||
|
||||
return syscall(__NR_inotify_rm_watch, fd, wd);
|
||||
return syscall(__NR_inotify_rm_watch, fd, wd);
|
||||
}
|
||||
|
||||
#endif /* _LINUX_INOTIFY_SYSCALLS_H */
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void inotify_exit(void) {
|
|||
notify_event *e;
|
||||
while((e = queue_dequeue(event_queue)))
|
||||
notify_event_del(e);
|
||||
queue_destroy(event_queue);
|
||||
queue_destroy(event_queue);
|
||||
event_queue = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,13 +69,13 @@ static void proc_event(struct inotify_event *iev) {
|
|||
return;
|
||||
}
|
||||
|
||||
/* lookup watch descriptors */
|
||||
watch_list = inotify_map_get_path(iev->wd);
|
||||
/* lookup watch descriptors */
|
||||
watch_list = inotify_map_get_path(iev->wd);
|
||||
|
||||
if (!watch_list) {
|
||||
logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd);
|
||||
return;
|
||||
}
|
||||
if (!watch_list) {
|
||||
logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd);
|
||||
return;
|
||||
}
|
||||
|
||||
for(i=0; i < watch_list->nr; i++) {
|
||||
|
||||
|
|
|
|||
50
src/list.c
50
src/list.c
|
|
@ -24,10 +24,10 @@ static void resize(struct list *l) {
|
|||
|
||||
struct list* list_create(void) {
|
||||
|
||||
struct list *list = xmalloc(sizeof(struct list));
|
||||
list->items = NULL;
|
||||
list->nr = 0;
|
||||
return list;
|
||||
struct list *list = xmalloc(sizeof(struct list));
|
||||
list->items = NULL;
|
||||
list->nr = 0;
|
||||
return list;
|
||||
}
|
||||
|
||||
struct list* list_copy(struct list *list) {
|
||||
|
|
@ -69,8 +69,8 @@ void list_clear_fn(struct list *list, clear_fn_t *fn) {
|
|||
|
||||
int list_insert(struct list *list, const void *item) {
|
||||
|
||||
if (!list)
|
||||
return -1;
|
||||
if (!list)
|
||||
return -1;
|
||||
|
||||
list->items = xrealloc(list->items, sizeof(list->items) * (++list->nr));
|
||||
list->items[list->nr - 1] = (void *) item;
|
||||
|
|
@ -80,7 +80,7 @@ int list_insert(struct list *list, const void *item) {
|
|||
|
||||
void* list_remove(struct list *list, unsigned index) {
|
||||
|
||||
void *item = NULL;
|
||||
void *item = NULL;
|
||||
|
||||
if (list && index < list->nr) {
|
||||
if (index < --list->nr) {
|
||||
|
|
@ -105,29 +105,29 @@ void* list_reduce(struct list *list) {
|
|||
|
||||
int list_indexof(struct list *list, const void *item) {
|
||||
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for(i=0; i < list->nr; i++) {
|
||||
for(i=0; i < list->nr; i++) {
|
||||
|
||||
if (list->items[i] == item)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
if (list->items[i] == item)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* list_lookup(struct list *list, const void *item, cmp_fn_t *fn) {
|
||||
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (fn) {
|
||||
for(i=0; i < list->nr; i++) {
|
||||
if (fn(list->items[i], item) == 0)
|
||||
return list->items[i];
|
||||
}
|
||||
} else {
|
||||
i = list_indexof(list, item);
|
||||
if (i >= 0)
|
||||
return list->items[i];
|
||||
}
|
||||
return NULL;
|
||||
if (fn) {
|
||||
for(i=0; i < list->nr; i++) {
|
||||
if (fn(list->items[i], item) == 0)
|
||||
return list->items[i];
|
||||
}
|
||||
} else {
|
||||
i = list_indexof(list, item);
|
||||
if (i >= 0)
|
||||
return list->items[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ unsigned logstrtolvl(const char *str) {
|
|||
|
||||
void logmsg(unsigned level, const char *fmt, ...) {
|
||||
|
||||
va_list vl;
|
||||
va_list vl;
|
||||
|
||||
if (!validmask(level, 1))
|
||||
die("log: invalid level: %x\n", level);
|
||||
|
|
@ -155,9 +155,9 @@ void logmsg(unsigned level, const char *fmt, ...) {
|
|||
|
||||
void logerrno(unsigned level, const char *prefix, int err) {
|
||||
|
||||
char *str = strerror(err);
|
||||
char *str = strerror(err);
|
||||
|
||||
if (str && level & mask) {
|
||||
if (str && level & mask) {
|
||||
|
||||
if (!validmask(level, 1))
|
||||
die("logerrno: invalid level: %x\n", level);
|
||||
|
|
@ -169,5 +169,5 @@ void logerrno(unsigned level, const char *prefix, int err) {
|
|||
fputs(str, logfd);
|
||||
fputc('\n', logfd);
|
||||
fflush(logfd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,13 +93,13 @@ static int rmwatch(const char *path, const char *name) {
|
|||
|
||||
int notify_init() {
|
||||
|
||||
if (!init) {
|
||||
if (!init) {
|
||||
if (inotify_init() < 0)
|
||||
return -1;
|
||||
init_ev_q = queue_init();
|
||||
init = 1;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void notify_exit() {
|
||||
|
|
@ -108,7 +108,7 @@ void notify_exit() {
|
|||
notify_event *e;
|
||||
while((e = queue_dequeue(init_ev_q)))
|
||||
notify_event_del(e);
|
||||
queue_destroy(init_ev_q);
|
||||
queue_destroy(init_ev_q);
|
||||
init_ev_q = NULL;
|
||||
|
||||
inotify_exit();
|
||||
|
|
@ -129,9 +129,9 @@ int notify_add_watch(const char *path) {
|
|||
|
||||
int notify_rm_watch(const char *path) {
|
||||
|
||||
if (!init)
|
||||
if (!init)
|
||||
die("inotify is not instantiated.");
|
||||
return rmwatch(path, NULL);
|
||||
return rmwatch(path, NULL);
|
||||
}
|
||||
|
||||
notify_event* notify_read() {
|
||||
|
|
|
|||
14
src/path.c
14
src/path.c
|
|
@ -25,16 +25,16 @@ static char path_null = '\0';
|
|||
|
||||
static inline int has_delim(const char *str) {
|
||||
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return strchr(str, '/') != NULL;
|
||||
return strchr(str, '/') != NULL;
|
||||
}
|
||||
|
||||
int is_abspath(const char *path) {
|
||||
|
||||
if (path == NULL || *path != '/')
|
||||
return 0;
|
||||
if (path == NULL || *path != '/')
|
||||
return 0;
|
||||
|
||||
for(; *path; path++) {
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ int is_abspath(const char *path) {
|
|||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int is_file(const char *path) {
|
||||
|
|
@ -147,7 +147,7 @@ char* path_normalize(const char *base, const char *name, unsigned dir) {
|
|||
strbuf_t sb = STRBUF_INIT;
|
||||
|
||||
if (base == NULL || has_delim(name))
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (*base == '~') {
|
||||
base++;
|
||||
|
|
|
|||
19
src/queue.c
19
src/queue.c
|
|
@ -19,7 +19,7 @@
|
|||
/* linked list node holding a chunk of queue elements */
|
||||
struct node {
|
||||
void *block[BLOCK_SIZE];
|
||||
struct node *next;
|
||||
struct node *next;
|
||||
};
|
||||
|
||||
struct ref {
|
||||
|
|
@ -28,22 +28,22 @@ struct ref {
|
|||
};
|
||||
|
||||
struct __queue {
|
||||
struct ref tail;
|
||||
struct ref head;
|
||||
struct ref tail;
|
||||
struct ref head;
|
||||
};
|
||||
|
||||
static void alloc_node(struct ref *head) {
|
||||
|
||||
struct node *n = xmalloc(sizeof(struct node));
|
||||
struct node *n = xmalloc(sizeof(struct node));
|
||||
|
||||
n->next = NULL;
|
||||
head->n = head->n->next = n;
|
||||
head->i = 0;
|
||||
head->n = head->n->next = n;
|
||||
head->i = 0;
|
||||
}
|
||||
|
||||
static void dealloc_node(struct ref *tail) {
|
||||
|
||||
struct node *next = tail->n->next;
|
||||
struct node *next = tail->n->next;
|
||||
|
||||
if (next) {
|
||||
xfree(tail->n);
|
||||
|
|
@ -81,10 +81,10 @@ void queue_enqueue(queue_t q, void *obj) {
|
|||
return;
|
||||
|
||||
if (q->head.i >= BLOCK_SIZE) {
|
||||
alloc_node(&q->head);
|
||||
alloc_node(&q->head);
|
||||
}
|
||||
|
||||
q->head.n->block[q->head.i++] = obj;
|
||||
q->head.n->block[q->head.i++] = obj;
|
||||
}
|
||||
|
||||
void* queue_dequeue(queue_t q) {
|
||||
|
|
@ -129,4 +129,3 @@ size_t queue_num_items(queue_t q) {
|
|||
len += BLOCK_SIZE;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
|
|||
264
src/rbtree.c
264
src/rbtree.c
|
|
@ -24,8 +24,8 @@
|
|||
/* node definition */
|
||||
typedef struct _rbn {
|
||||
const void *key;
|
||||
struct _rbn *child[2];
|
||||
unsigned char color;
|
||||
struct _rbn *child[2];
|
||||
unsigned char color;
|
||||
} rbnode;
|
||||
|
||||
#define is_red(n) ((n) != NULL && (n)->color == RB_RED)
|
||||
|
|
@ -33,14 +33,14 @@ typedef struct _rbn {
|
|||
|
||||
static rbnode* node_alloc(const void *key) {
|
||||
|
||||
rbnode *n = xmalloc(sizeof(rbnode));
|
||||
rbnode *n = xmalloc(sizeof(rbnode));
|
||||
|
||||
n->key = key;
|
||||
n->color = RB_RED;
|
||||
n->child[0] = NULL;
|
||||
n->child[1] = NULL;
|
||||
n->key = key;
|
||||
n->color = RB_RED;
|
||||
n->child[0] = NULL;
|
||||
n->child[1] = NULL;
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -48,16 +48,16 @@ static rbnode* node_alloc(const void *key) {
|
|||
*/
|
||||
static void node_dealloc(rbnode *n, void (*dealloc)(void *)) {
|
||||
|
||||
if (!n)
|
||||
return;
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
if (dealloc)
|
||||
dealloc((void *)n->key);
|
||||
|
||||
node_dealloc(n->child[0], dealloc);
|
||||
node_dealloc(n->child[1], dealloc);
|
||||
node_dealloc(n->child[0], dealloc);
|
||||
node_dealloc(n->child[1], dealloc);
|
||||
|
||||
free(n);
|
||||
free(n);
|
||||
}
|
||||
|
||||
#ifdef __DEBUG__
|
||||
|
|
@ -65,43 +65,43 @@ static void node_dealloc(rbnode *n, void (*dealloc)(void *)) {
|
|||
|
||||
static int rb_assert_r(rbnode *node, int (*cmp)(const void *, const void *)) {
|
||||
|
||||
int rh, lh;
|
||||
rbnode *ln, *rn;
|
||||
int rh, lh;
|
||||
rbnode *ln, *rn;
|
||||
|
||||
if (node == NULL)
|
||||
return 1;
|
||||
if (node == NULL)
|
||||
return 1;
|
||||
|
||||
ln = node->child[0];
|
||||
rn = node->child[1];
|
||||
ln = node->child[0];
|
||||
rn = node->child[1];
|
||||
|
||||
if (is_red(node)) {
|
||||
if (is_red(node)) {
|
||||
/* double red violation */
|
||||
if (is_red(ln) || is_red(rn)) {
|
||||
rb_err("Double red violation");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (is_red(ln) || is_red(rn)) {
|
||||
rb_err("Double red violation");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lh = rb_assert_r(ln, cmp);
|
||||
rh = rb_assert_r(rn, cmp);
|
||||
lh = rb_assert_r(ln, cmp);
|
||||
rh = rb_assert_r(rn, cmp);
|
||||
|
||||
if ( (ln && cmp(ln->key, node->key) >= 0) &&
|
||||
(rn && cmp(rn->key, node->key) <= 0) ) {
|
||||
rb_err("Binary tree violation");
|
||||
return 0;
|
||||
}
|
||||
rb_err("Binary tree violation");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rh != 0 && lh != 0) {
|
||||
if (rh != 0 && lh != 0) {
|
||||
|
||||
if (rh != lh) {
|
||||
if (rh != lh) {
|
||||
rb_err("Black height violation");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return is_red(node) ? lh : lh+1;
|
||||
}
|
||||
return is_red(node) ? lh : lh+1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#undef rb_err
|
||||
|
||||
|
|
@ -119,35 +119,35 @@ static void rb_assert(rbtree *tree) {
|
|||
*/
|
||||
static void rbwalk(rbnode *n, void (*action)(const void *)) {
|
||||
|
||||
if (!n)
|
||||
return;
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
rbwalk(n->child[0], action);
|
||||
rbwalk(n->child[0], action);
|
||||
action(n->key);
|
||||
rbwalk(n->child[1], action);
|
||||
rbwalk(n->child[1], action);
|
||||
}
|
||||
|
||||
static rbnode* rotate_single(rbnode *root, int dir) {
|
||||
|
||||
rbnode *save = root->child[!dir];
|
||||
rbnode *save = root->child[!dir];
|
||||
|
||||
root->child[!dir] = save->child[dir];
|
||||
save->child[dir] = root;
|
||||
root->child[!dir] = save->child[dir];
|
||||
save->child[dir] = root;
|
||||
|
||||
root->color = RB_RED;
|
||||
save->color = RB_BLACK;
|
||||
root->color = RB_RED;
|
||||
save->color = RB_BLACK;
|
||||
|
||||
return save;
|
||||
return save;
|
||||
}
|
||||
|
||||
static rbnode* rotate_double(rbnode *root, int dir) {
|
||||
root->child[!dir] = rotate_single(root->child[!dir], !dir);
|
||||
return rotate_single(root, dir);
|
||||
root->child[!dir] = rotate_single(root->child[!dir], !dir);
|
||||
return rotate_single(root, dir);
|
||||
}
|
||||
|
||||
int rbtree_is_empty(rbtree *tree) {
|
||||
|
||||
return tree == NULL || tree->root == NULL;
|
||||
return tree == NULL || tree->root == NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -155,30 +155,30 @@ int rbtree_is_empty(rbtree *tree) {
|
|||
*/
|
||||
void* rbtree_search(rbtree *tree, const void *key) {
|
||||
|
||||
rbnode *n;
|
||||
rbnode *n;
|
||||
|
||||
if (!tree || !tree->cmp_fn)
|
||||
return NULL;
|
||||
if (!tree || !tree->cmp_fn)
|
||||
return NULL;
|
||||
|
||||
n = tree->root;
|
||||
n = tree->root;
|
||||
|
||||
while(n) {
|
||||
while(n) {
|
||||
int cmp = tree->cmp_fn(n->key, key);
|
||||
|
||||
if (cmp == 0)
|
||||
return (void *) n->key;
|
||||
if (cmp == 0)
|
||||
return (void *) n->key;
|
||||
|
||||
n = n->child[cmp < 0];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rbtree_walk(rbtree *tree, void (*action)(const void *)) {
|
||||
|
||||
if (!tree || !action)
|
||||
return;
|
||||
if (!tree || !action)
|
||||
return;
|
||||
|
||||
rbwalk(tree->root, action);
|
||||
rbwalk(tree->root, action);
|
||||
|
||||
#ifdef __DEBUG__
|
||||
rb_assert(tree);
|
||||
|
|
@ -187,11 +187,11 @@ void rbtree_walk(rbtree *tree, void (*action)(const void *)) {
|
|||
|
||||
void rbtree_free(rbtree *tree, void (*free_fn)(void *)) {
|
||||
|
||||
if (!tree)
|
||||
return;
|
||||
if (!tree)
|
||||
return;
|
||||
|
||||
node_dealloc(tree->root, free_fn);
|
||||
tree->root = NULL;
|
||||
node_dealloc(tree->root, free_fn);
|
||||
tree->root = NULL;
|
||||
|
||||
#ifdef __DEBUG__
|
||||
rb_assert(tree);
|
||||
|
|
@ -200,70 +200,70 @@ void rbtree_free(rbtree *tree, void (*free_fn)(void *)) {
|
|||
|
||||
int rbtree_insert(rbtree *tree, const void *key) {
|
||||
|
||||
rbnode head = {0};
|
||||
rbnode head = {0};
|
||||
|
||||
/* grandparent and parent */
|
||||
rbnode *g, *t;
|
||||
/* grandparent and parent */
|
||||
rbnode *g, *t;
|
||||
|
||||
/* iterator and parent */
|
||||
rbnode *p, *q;
|
||||
/* iterator and parent */
|
||||
rbnode *p, *q;
|
||||
|
||||
int dir = 0, last = 0;
|
||||
int dir = 0, last = 0;
|
||||
|
||||
if (!tree || !tree->cmp_fn)
|
||||
return -1;
|
||||
|
||||
if (!tree->root) {
|
||||
tree->root = q = node_alloc(key);
|
||||
if (!tree->root) {
|
||||
tree->root = q = node_alloc(key);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
t = &head;
|
||||
g = p = NULL;
|
||||
q = t->child[1] = tree->root;
|
||||
t = &head;
|
||||
g = p = NULL;
|
||||
q = t->child[1] = tree->root;
|
||||
|
||||
/* somewhere in here, there should be dragons */
|
||||
|
||||
for(;;) {
|
||||
for(;;) {
|
||||
int cmp;
|
||||
|
||||
if (q == NULL) {
|
||||
p->child[dir] = q = node_alloc(key);
|
||||
} else if (is_red(q->child[0]) && is_red(q->child[1])) {
|
||||
/* color flip case */
|
||||
q->color = RB_RED;
|
||||
q->child[0]->color = RB_BLACK;
|
||||
q->child[1]->color = RB_BLACK;
|
||||
}
|
||||
if (q == NULL) {
|
||||
p->child[dir] = q = node_alloc(key);
|
||||
} else if (is_red(q->child[0]) && is_red(q->child[1])) {
|
||||
/* color flip case */
|
||||
q->color = RB_RED;
|
||||
q->child[0]->color = RB_BLACK;
|
||||
q->child[1]->color = RB_BLACK;
|
||||
}
|
||||
|
||||
/* fix red validation */
|
||||
if (is_red(q) && is_red(p)) {
|
||||
int dir2 = (t->child[1] == g);
|
||||
if (q == p->child[last])
|
||||
t->child[dir2] = rotate_single(g, !last);
|
||||
else
|
||||
t->child[dir2] = rotate_double(g, !last);
|
||||
}
|
||||
/* fix red validation */
|
||||
if (is_red(q) && is_red(p)) {
|
||||
int dir2 = (t->child[1] == g);
|
||||
if (q == p->child[last])
|
||||
t->child[dir2] = rotate_single(g, !last);
|
||||
else
|
||||
t->child[dir2] = rotate_double(g, !last);
|
||||
}
|
||||
|
||||
cmp = tree->cmp_fn(q->key, key);
|
||||
|
||||
if (cmp == 0)
|
||||
break;
|
||||
if (cmp == 0)
|
||||
break;
|
||||
|
||||
last = dir;
|
||||
last = dir;
|
||||
dir = cmp < 0;
|
||||
|
||||
if (g)
|
||||
t = g;
|
||||
g = p, p = q;
|
||||
q = q->child[dir];
|
||||
}
|
||||
if (g)
|
||||
t = g;
|
||||
g = p, p = q;
|
||||
q = q->child[dir];
|
||||
}
|
||||
|
||||
tree->root = head.child[1];
|
||||
tree->root = head.child[1];
|
||||
|
||||
done:
|
||||
/* root should be black */
|
||||
tree->root->color = RB_BLACK;
|
||||
/* root should be black */
|
||||
tree->root->color = RB_BLACK;
|
||||
|
||||
#ifdef __DEBUG__
|
||||
rb_assert(tree);
|
||||
|
|
@ -274,38 +274,38 @@ done:
|
|||
|
||||
void* rbtree_delete(rbtree *tree, const void *key) {
|
||||
|
||||
rbnode head = {0};
|
||||
rbnode head = {0};
|
||||
|
||||
/* helpers*/
|
||||
rbnode *q, *p, *g, *s;
|
||||
/* helpers*/
|
||||
rbnode *q, *p, *g, *s;
|
||||
|
||||
/* found item */
|
||||
rbnode *f = NULL, *ret = NULL;
|
||||
/* found item */
|
||||
rbnode *f = NULL, *ret = NULL;
|
||||
|
||||
int dir = 1, dir2, last;
|
||||
int dir = 1, dir2, last;
|
||||
|
||||
if (rbtree_is_empty(tree) || !tree->cmp_fn)
|
||||
return 0;
|
||||
if (rbtree_is_empty(tree) || !tree->cmp_fn)
|
||||
return 0;
|
||||
|
||||
q = &head;
|
||||
g = p = NULL;
|
||||
q->child[1] = tree->root;
|
||||
q = &head;
|
||||
g = p = NULL;
|
||||
q->child[1] = tree->root;
|
||||
|
||||
/* more dragons (killed some of them though) */
|
||||
/* more dragons (killed some of them though) */
|
||||
|
||||
while(q->child[dir]) {
|
||||
while(q->child[dir]) {
|
||||
int cmp;
|
||||
|
||||
g = p, p = q;
|
||||
g = p, p = q;
|
||||
q = q->child[dir];
|
||||
last = dir;
|
||||
|
||||
cmp = tree->cmp_fn(q->key, key);
|
||||
dir = cmp < 0;
|
||||
if (cmp == 0)
|
||||
f = q;
|
||||
dir = cmp < 0;
|
||||
if (cmp == 0)
|
||||
f = q;
|
||||
|
||||
if (is_red(q) || is_red(q->child[dir]))
|
||||
if (is_red(q) || is_red(q->child[dir]))
|
||||
continue;
|
||||
|
||||
if (is_red(q->child[!dir])) {
|
||||
|
|
@ -331,25 +331,25 @@ void* rbtree_delete(rbtree *tree, const void *key) {
|
|||
g->child[dir2]->child[0]->color = RB_BLACK;
|
||||
g->child[dir2]->child[1]->color = RB_BLACK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* remove if found */
|
||||
if (f) {
|
||||
/* remove if found */
|
||||
if (f) {
|
||||
ret = (void*)f->key;
|
||||
if (f != q)
|
||||
f->key = q->key;
|
||||
swap(p, 1, q) = swap(q, 0, NULL);
|
||||
xfree(q);
|
||||
}
|
||||
}
|
||||
|
||||
tree->root = head.child[1];
|
||||
if (tree->root)
|
||||
tree->root->color = RB_BLACK;
|
||||
if (tree->root)
|
||||
tree->root->color = RB_BLACK;
|
||||
|
||||
#ifdef __DEBUG__
|
||||
rb_assert(tree);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
struct _rbn *root;
|
||||
struct _rbn *root;
|
||||
/* user defined operations */
|
||||
int (*cmp_fn)(const void *, const void *);
|
||||
} rbtree;
|
||||
|
|
|
|||
|
|
@ -167,5 +167,3 @@ char** str_list_export(struct str_list *list) {
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
50
src/strbuf.c
50
src/strbuf.c
|
|
@ -22,8 +22,8 @@ char strbuf_null = '\0';
|
|||
|
||||
void strbuf_init(strbuf_t *s) {
|
||||
|
||||
s->buf = &strbuf_null;
|
||||
s->alloc_size = s->len = 0;
|
||||
s->buf = &strbuf_null;
|
||||
s->alloc_size = s->len = 0;
|
||||
}
|
||||
|
||||
size_t strbuf_avail(strbuf_t *s) {
|
||||
|
|
@ -34,13 +34,13 @@ size_t strbuf_avail(strbuf_t *s) {
|
|||
void strbuf_expand(strbuf_t *s, size_t len) {
|
||||
|
||||
if (s->len + len + 1 < s->alloc_size)
|
||||
return;
|
||||
return;
|
||||
if (!s->alloc_size)
|
||||
s->buf = NULL;
|
||||
|
||||
do
|
||||
s->alloc_size += CHNK_SIZE;
|
||||
while(s->len + len + 1 > s->alloc_size);
|
||||
do
|
||||
s->alloc_size += CHNK_SIZE;
|
||||
while(s->len + len + 1 > s->alloc_size);
|
||||
|
||||
s->buf = xrealloc(s->buf, s->alloc_size);
|
||||
}
|
||||
|
|
@ -66,18 +66,18 @@ void strbuf_setlen(strbuf_t *s, size_t len) {
|
|||
|
||||
char* strbuf_release(strbuf_t *s) {
|
||||
|
||||
char *ret;
|
||||
char *ret;
|
||||
|
||||
if (!s->alloc_size)
|
||||
if (!s->alloc_size)
|
||||
ret = xmallocz(1);
|
||||
else if (s->len + 1 != s->alloc_size)
|
||||
ret = xrealloc(s->buf, s->len + 1);
|
||||
else
|
||||
ret = s->buf;
|
||||
ret = xrealloc(s->buf, s->len + 1);
|
||||
else
|
||||
ret = s->buf;
|
||||
|
||||
strbuf_init(s);
|
||||
strbuf_init(s);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void strbuf_free(strbuf_t *s) {
|
||||
|
|
@ -131,10 +131,10 @@ void strbuf_appendf(strbuf_t *s, const char *fmt, ...) {
|
|||
va_end(va);
|
||||
|
||||
if (len > 0) {
|
||||
strbuf_expand(s, len);
|
||||
va_start(va, fmt);
|
||||
len = strbuf_append_va(s, fmt, va);
|
||||
va_end(va);
|
||||
strbuf_expand(s, len);
|
||||
va_start(va, fmt);
|
||||
len = strbuf_append_va(s, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,8 +186,8 @@ void strbuf_term(strbuf_t *s, char ch) {
|
|||
|
||||
void strbuf_trim(strbuf_t *s) {
|
||||
|
||||
strbuf_rtrim(s);
|
||||
strbuf_ltrim(s);
|
||||
strbuf_rtrim(s);
|
||||
strbuf_ltrim(s);
|
||||
}
|
||||
|
||||
void strbuf_rtrim(strbuf_t *s) {
|
||||
|
|
@ -201,14 +201,14 @@ void strbuf_ltrim(strbuf_t *s) {
|
|||
|
||||
size_t i, of = 0;
|
||||
|
||||
for(; of < s->len && isspace(s->buf[of]); of++);
|
||||
for(; of < s->len && isspace(s->buf[of]); of++);
|
||||
|
||||
if (of < 1)
|
||||
return;
|
||||
if (of < 1)
|
||||
return;
|
||||
|
||||
s->len -= of;
|
||||
for(i=0; i <= s->len; i++)
|
||||
s->buf[i] = s->buf[i + of];
|
||||
s->len -= of;
|
||||
for(i=0; i <= s->len; i++)
|
||||
s->buf[i] = s->buf[i + of];
|
||||
}
|
||||
|
||||
void strbuf_rev(strbuf_t *s) {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# Helper for touching a number of files in a directory.
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: $0 <dir> [ <nfiles> ]"
|
||||
exit 1
|
||||
echo "usage: $0 <dir> [ <nfiles> ]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $1 ]; then
|
||||
|
|
@ -23,5 +23,5 @@ if [ $# -gt 1 ]; then
|
|||
fi
|
||||
|
||||
for i in `seq 0 ${NFILES}`; do
|
||||
touch "${1}/file${i}"
|
||||
touch "${1}/file${i}"
|
||||
done
|
||||
|
|
|
|||
|
|
@ -5,42 +5,42 @@
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
fscrawl_t crawl;
|
||||
unsigned int c_ent = 0, verbose = 0;
|
||||
fscrawl_t crawl;
|
||||
unsigned int c_ent = 0, verbose = 0;
|
||||
time_t t1, t2, tdiff;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
if (argc > 2 && (argv[2][0] == '1' && argv[2][1] == '\0'))
|
||||
verbose = 1;
|
||||
|
||||
crawl = fsc_open(argv[1]);
|
||||
crawl = fsc_open(argv[1]);
|
||||
|
||||
if (crawl == NULL) {
|
||||
printf("Invalid path\n");
|
||||
return 1;
|
||||
}
|
||||
if (crawl == NULL) {
|
||||
printf("Invalid path\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
t1 = time(NULL);
|
||||
for(;;) {
|
||||
fs_entry *ent = fsc_read(crawl);
|
||||
for(;;) {
|
||||
fs_entry *ent = fsc_read(crawl);
|
||||
|
||||
if (!ent)
|
||||
break;
|
||||
break;
|
||||
|
||||
if (verbose)
|
||||
printf("%s%s%c\n", ent->base, ent->name,
|
||||
ent->dir ? '/' : '\0');
|
||||
|
||||
c_ent++;
|
||||
}
|
||||
c_ent++;
|
||||
}
|
||||
t2 = time(NULL);
|
||||
|
||||
fsc_close(crawl);
|
||||
|
||||
tdiff = t2 - t1;
|
||||
printf("Nodes: %u\n"
|
||||
printf("Nodes: %u\n"
|
||||
"Time (sec): %ld\n", c_ent, tdiff);
|
||||
|
||||
printf("Node/sec: ");
|
||||
|
|
@ -50,5 +50,5 @@ int main(int argc, char *argv[]) {
|
|||
puts("INF");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,33 +4,34 @@
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
notify_event *event;
|
||||
notify_event *event;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
notify_init();
|
||||
notify_init();
|
||||
|
||||
if (!notify_add_watch(argv[1]))
|
||||
return 1;
|
||||
if (!notify_add_watch(argv[1]))
|
||||
return 1;
|
||||
|
||||
printf("begin watching on: %s\n", argv[1]);
|
||||
printf("begin watching on: %s\n", argv[1]);
|
||||
|
||||
for (;;) {
|
||||
for (;;) {
|
||||
|
||||
event = notify_read();
|
||||
event = notify_read();
|
||||
|
||||
if (event == NULL)
|
||||
continue;
|
||||
if (event == NULL)
|
||||
continue;
|
||||
|
||||
printf("====================\n"
|
||||
"Type: %s\n"
|
||||
"Path: %s\n"
|
||||
"Filename: %s\n"
|
||||
"Directory: %u\n"
|
||||
"====================\n"
|
||||
, notify_event_typetostr(event), event->path, event->filename, event->dir);
|
||||
}
|
||||
printf("====================\n"
|
||||
"Type: %s\n"
|
||||
"Path: %s\n"
|
||||
"Filename: %s\n"
|
||||
"Directory: %u\n"
|
||||
"====================\n"
|
||||
, notify_event_typetostr(event), event->path,
|
||||
event->filename, event->dir);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,5 +95,5 @@ int main() {
|
|||
if (q)
|
||||
queue_destroy(q);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ void test_release() {
|
|||
|
||||
str = strbuf_release(&b);
|
||||
|
||||
printf("released |%s|\n", str);
|
||||
printf("released |%s|\n", str);
|
||||
|
||||
free(str);
|
||||
free(str);
|
||||
}
|
||||
|
||||
void test_release_empty() {
|
||||
|
|
@ -144,7 +144,7 @@ void test_trim() {
|
|||
strbuf_append_repeat(&b, ' ', 4);
|
||||
strbuf_append(&b, "abcdef", 6);
|
||||
|
||||
print_strbuf(&b);
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_append(&b, "012345678901234567890123456789", 30);
|
||||
strbuf_append_ch(&b, 'a');
|
||||
|
|
@ -156,9 +156,9 @@ void test_trim() {
|
|||
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_ltrim(&b);
|
||||
strbuf_ltrim(&b);
|
||||
|
||||
print_strbuf(&b);
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_free(&b);
|
||||
}
|
||||
|
|
@ -171,9 +171,9 @@ void test_rev() {
|
|||
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_rev(&b);
|
||||
strbuf_rev(&b);
|
||||
|
||||
print_strbuf(&b);
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_free(&b);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ void __assert_str(const char *file, int line, const char *func, const char *a, c
|
|||
|
||||
if (strcmp(a, b) != 0)
|
||||
__uexit(file, line, func, "\"%s\" != \"%s\"\n", a, b);
|
||||
|
||||
}
|
||||
|
||||
void utest_init_RNG() {
|
||||
|
|
|
|||
Reference in a new issue