2012-07-18 20:19:48 +07:00
|
|
|
#pragma once
|
2011-12-28 22:33:26 +07:00
|
|
|
#include "macro.h"
|
|
|
|
|
|
|
|
#include <limits.h>
|
2012-05-24 11:19:20 +07:00
|
|
|
#include <stdbool.h>
|
2013-11-14 09:19:15 +07:00
|
|
|
#include <stdlib.h>
|
2011-12-28 22:33:26 +07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2013-03-20 03:44:59 +07:00
|
|
|
#include <sys/stat.h>
|
2011-12-28 22:33:26 +07:00
|
|
|
|
|
|
|
|
2011-12-27 23:38:26 +07:00
|
|
|
char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1)));
|
|
|
|
#define streq(a, b) (strcmp((a), (b)) == 0)
|
2011-12-28 22:33:26 +07:00
|
|
|
#define strstartswith(a, b) (strncmp(a, b, strlen(b)) == 0)
|
2011-12-27 23:38:26 +07:00
|
|
|
void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
|
|
|
|
|
2012-05-24 06:27:23 +07:00
|
|
|
ssize_t read_str_safe(int fd, char *buf, size_t buflen) _must_check_ __attribute__((nonnull(2)));
|
2012-01-17 00:46:01 +07:00
|
|
|
ssize_t write_str_safe(int fd, const char *buf, size_t buflen) __attribute__((nonnull(2)));
|
2012-05-24 06:27:23 +07:00
|
|
|
int read_str_long(int fd, long *value, int base) _must_check_ __attribute__((nonnull(2)));
|
|
|
|
int read_str_ulong(int fd, unsigned long *value, int base) _must_check_ __attribute__((nonnull(2)));
|
2011-12-27 23:38:26 +07:00
|
|
|
char *strchr_replace(char *s, int c, char r);
|
2012-05-24 06:27:23 +07:00
|
|
|
bool path_is_absolute(const char *p) _must_check_ __attribute__((nonnull(1)));
|
|
|
|
char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(1)));
|
2013-07-15 11:58:44 +07:00
|
|
|
int mkdir_p(const char *path, int len, mode_t mode);
|
2013-07-15 12:05:52 +07:00
|
|
|
int mkdir_parents(const char *path, mode_t mode);
|
2012-05-24 06:27:23 +07:00
|
|
|
int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2)));
|
2012-01-08 10:02:29 +07:00
|
|
|
char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2)));
|
|
|
|
char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2)));
|
2012-11-28 10:44:00 +07:00
|
|
|
|
|
|
|
extern const struct kmod_ext {
|
|
|
|
const char *ext;
|
|
|
|
size_t len;
|
|
|
|
} kmod_exts[];
|
|
|
|
#define KMOD_EXT_UNC 0
|
2012-11-28 23:25:50 +07:00
|
|
|
bool path_ends_with_kmod_ext(const char *path, size_t len) __attribute__((nonnull(1)));
|
2012-11-28 10:44:00 +07:00
|
|
|
|
2012-01-17 21:10:42 +07:00
|
|
|
unsigned long long stat_mstamp(const struct stat *st);
|
2012-06-06 07:02:11 +07:00
|
|
|
unsigned long long ts_usec(const struct timespec *ts);
|
2011-12-27 23:38:26 +07:00
|
|
|
|
2012-05-22 06:22:12 +07:00
|
|
|
#define get_unaligned(ptr) \
|
|
|
|
({ \
|
|
|
|
struct __attribute__((packed)) { \
|
|
|
|
typeof(*(ptr)) __v; \
|
|
|
|
} *__p = (typeof(__p)) (ptr); \
|
|
|
|
__p->__v; \
|
|
|
|
})
|
|
|
|
|
2012-05-22 06:43:39 +07:00
|
|
|
#define put_unaligned(val, ptr) \
|
2012-05-22 06:22:12 +07:00
|
|
|
do { \
|
|
|
|
struct __attribute__((packed)) { \
|
|
|
|
typeof(*(ptr)) __v; \
|
|
|
|
} *__p = (typeof(__p)) (ptr); \
|
|
|
|
__p->__v = (val); \
|
|
|
|
} while(0)
|
2013-08-22 11:10:13 +07:00
|
|
|
|
|
|
|
static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
|
|
|
|
{
|
|
|
|
return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1));
|
|
|
|
}
|
2013-11-14 09:19:15 +07:00
|
|
|
|
|
|
|
static inline void freep(void *p) {
|
|
|
|
free(*(void**) p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _cleanup_free_ _cleanup_(freep)
|