23RCSID(
"$Id: a690958294f1f7159bee7fe8c61427865d4d2c61 $")
25#include <freeradius-devel/util/dbuff.h>
26#include <freeradius-devel/util/sbuff.h>
27#include <freeradius-devel/util/syserror.h>
37#define FR_PUT_LE16(a, val)\
39 a[1] = ((uint16_t) (val)) >> 8;\
40 a[0] = ((uint16_t) (val)) & 0xff;\
53 memset(&act, 0,
sizeof(act));
55 sigemptyset(&act.sa_mask);
56 act.sa_handler = func;
58 if (sigaction(sig, &act, NULL) < 0) {
63 if (signal(sig, func) < 0) {
82 memset(&act, 0,
sizeof(act));
84 sigemptyset(&act.sa_mask);
85 act.sa_handler = SIG_DFL;
87 return sigaction(sig, &act, NULL);
89 return signal(sig, SIG_DFL);
94#error "missing definition for F_WRLCK, all file locks will fail"
112 fl.l_whence = SEEK_CUR;
114 return fcntl(fd, cmd, (
void *)&fl);
122 return rad_lock(fd, lock_len, F_SETLKW, F_WRLCK);
135 return rad_lock(fd, lock_len, F_SETLK, F_WRLCK);
147 return rad_lock(fd, lock_len, F_SETLK, F_UNLCK);
167 if (errno == ERANGE) {
176 if (errno == ERANGE)
goto error;
198 if (errno == ERANGE) {
207 if (errno == ERANGE)
goto error;
218 if (!str || !size)
return NULL;
220 memcpy(&q, &str,
sizeof(q));
221 for (q = q + size; q > str && isspace((
uint8_t) *q); q--);
230 for (p = str; *p !=
'\0'; p++) *p = tolower(*p);
249 flags = fcntl(fd, F_GETFL, NULL);
256 if (fcntl(fd, F_SETFL, flags) < 0) {
277 flags = fcntl(fd, F_GETFL, NULL);
283 if (!(flags & O_NONBLOCK))
return flags;
286 if (fcntl(fd, F_SETFL, flags) < 0) {
321 for (i = 0; i <
inlen; i++) {
325 if ((
size_t)(
out - start) >= outlen) {
336 }
else if ((i == (
inlen - 1)) || ((
size_t)(
out - start) >= (outlen - 1))) {
343 if ((c & 0xe0) == 0xc0) {
348 if ((i ==
inlen) || ((
size_t)(
out - start) >= (outlen - 1))) {
355 FR_PUT_LE16(
out, ((c & 0xf) << 12) | ((c2 & 0x3f) << 6) | (c3 & 0x3f));
372 char buff[] =
"00000000000000000000000000000000000000000000";
376#ifndef WORDS_BIGENDIAN
384 memcpy(
n, &num,
sizeof(
n));
386 for (i = 0; i < 128; i++) {
390 carry = (
n[h] >= 0x8000000000000000);
393 n[h] = ((
n[h] << 1) & 0xffffffffffffffff) + (
n[l] >= 0x8000000000000000);
394 n[l] = ((
n[l] << 1) & 0xffffffffffffffff);
397 for (j =
sizeof(
buff) - 2; j >= 0; j--) {
399 carry = (
buff[j] >
'9');
400 if (carry)
buff[j] -= 10;
404 while ((*p ==
'0') && (p < &
buff[
sizeof(
buff) - 2])) p++;
435 if (start >= end)
return;
437#define SWAP(_a, _b) \
439 void const *_tmp = to_sort[_a]; \
440 to_sort[_a] = to_sort[_b]; \
441 to_sort[_b] = _tmp; \
444 pivot = to_sort[end];
445 for (pi = start, i = start; i < end; i++) {
446 if (cmp(to_sort[i], pivot) < 0) {
460 UNUSED void *private_data)
478 for (i = 0; i < length; i++) result |= a[i] ^ b[i];
492 char const *p = strrchr(path,
'/');
508 char const *p_p, *p_c, *p_pn, *p_cn;
510 if (!path)
return NULL;
511 if (!common)
return NULL;
516 while ((p_pn = strchr(p_p,
'/')) != NULL) {
517 p_cn = strchr(p_c,
'/');
518 if (!p_cn) p_cn = p_c + strlen(p_c);
520 if ((p_pn - p_p) != (p_cn - p_c))
break;
521 if (strncmp(p_p, p_c, p_pn - p_p) != 0)
break;
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
static uint8_t depth(fr_minmax_heap_index_t i)
void fr_quick_sort(void const *to_sort[], int start, int end, fr_cmp_t cmp)
Quick sort an array of pointers using a comparator.
int fr_unset_signal(int sig)
Uninstall a signal for a specific handler.
int fr_strtoull(uint64_t *out, char **end, char const *value)
Consume the integer (or hex) portion of a value string.
int fr_set_signal(int sig, sig_t func)
Sets a signal handler using sigaction if available, else signal.
#define FR_PUT_LE16(a, val)
int rad_unlockfd(int fd, int lock_len)
int fr_nonblock(UNUSED int fd)
char const * fr_filename_common_trim(char const *path, char const *common)
Get the filename from a path.
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen)
Convert UTF8 string to UCS2 encoding.
int fr_strtoll(int64_t *out, char **end, char const *value)
Consume the integer (or hex) portion of a value string.
int8_t fr_pointer_cmp(void const *a, void const *b)
Compares two pointers.
char * fr_trim(char const *str, size_t size)
Trim whitespace from the end of a string.
static int rad_lock(int fd, int lock_len, int cmd, int type)
char * fr_tolower(char *str)
int rad_lockfd(int fd, int lock_len)
int rad_lockfd_nonblock(int fd, int lock_len)
int fr_blocking(UNUSED int fd)
char const * fr_filename(char const *path)
Get the filename from a path.
size_t fr_snprint_uint128(char *out, size_t outlen, uint128_t const num)
Write 128bit unsigned integer to buffer.
int fr_digest_cmp(uint8_t const *a, uint8_t const *b, size_t length)
Do a comparison of two authentication digests by comparing the FULL data.
int8_t(* fr_cmp_t)(void const *a, void const *b)
static char buff[sizeof("18446744073709551615")+3]
fr_aka_sim_id_type_t type
size_t strlcpy(char *dst, char const *src, size_t siz)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static size_t char fr_sbuff_t size_t inlen
static size_t char ** out