23 RCSID(
"$Id: b20d703963b162c9196c6958a732aa2950b29658 $")
25 #include <freeradius-devel/util/dbuff.h>
26 #include <freeradius-devel/util/sbuff.h>
27 #include <freeradius-devel/util/syserror.h>
36 #define FR_PUT_LE16(a, val)\
38 a[1] = ((uint16_t) (val)) >> 8;\
39 a[0] = ((uint16_t) (val)) & 0xff;\
52 memset(&act, 0,
sizeof(act));
54 sigemptyset(&act.sa_mask);
55 act.sa_handler = func;
57 if (sigaction(sig, &act, NULL) < 0) {
62 if (signal(sig, func) < 0) {
81 memset(&act, 0,
sizeof(act));
83 sigemptyset(&act.sa_mask);
84 act.sa_handler = SIG_DFL;
86 return sigaction(sig, &act, NULL);
88 return signal(sig, SIG_DFL);
93 #error "missing definition for F_WRLCK, all file locks will fail"
111 fl.l_whence = SEEK_CUR;
113 return fcntl(fd, cmd, (
void *)&fl);
121 return rad_lock(fd, lock_len, F_SETLKW, F_WRLCK);
134 return rad_lock(fd, lock_len, F_SETLK, F_WRLCK);
146 return rad_lock(fd, lock_len, F_SETLK, F_UNLCK);
166 if (errno == ERANGE) {
175 if (errno == ERANGE)
goto error;
197 if (errno == ERANGE) {
206 if (errno == ERANGE)
goto error;
217 if (!str || !size)
return NULL;
219 memcpy(&q, &str,
sizeof(q));
220 for (q = q + size; q > str && isspace((
uint8_t) *q); q--);
229 for (p = str; *p !=
'\0'; p++) *p = tolower(*p);
248 flags = fcntl(fd, F_GETFL, NULL);
255 if (fcntl(fd, F_SETFL, flags) < 0) {
276 flags = fcntl(fd, F_GETFL, NULL);
282 if (!(flags & O_NONBLOCK))
return flags;
285 if (fcntl(fd, F_SETFL, flags) < 0) {
320 for (i = 0; i <
inlen; i++) {
324 if ((
size_t)(
out - start) >= outlen) {
335 }
else if ((i == (
inlen - 1)) || ((
size_t)(
out - start) >= (outlen - 1))) {
342 if ((c & 0xe0) == 0xc0) {
347 if ((i ==
inlen) || ((
size_t)(
out - start) >= (outlen - 1))) {
354 FR_PUT_LE16(
out, ((c & 0xf) << 12) | ((c2 & 0x3f) << 6) | (c3 & 0x3f));
371 char buff[] =
"00000000000000000000000000000000000000000000";
375 #ifndef WORDS_BIGENDIAN
383 memcpy(
n, &num,
sizeof(
n));
385 for (i = 0; i < 128; i++) {
389 carry = (
n[h] >= 0x8000000000000000);
392 n[h] = ((
n[h] << 1) & 0xffffffffffffffff) + (
n[l] >= 0x8000000000000000);
393 n[l] = ((
n[l] << 1) & 0xffffffffffffffff);
396 for (j =
sizeof(
buff) - 2; j >= 0; j--) {
398 carry = (
buff[j] >
'9');
399 if (carry)
buff[j] -= 10;
403 while ((*p ==
'0') && (p < &
buff[
sizeof(
buff) - 2])) p++;
434 if (start >= end)
return;
436 #define SWAP(_a, _b) \
438 void const *_tmp = to_sort[_a]; \
439 to_sort[_a] = to_sort[_b]; \
440 to_sort[_b] = _tmp; \
443 pivot = to_sort[end];
444 for (pi = start, i = start; i < end; i++) {
445 if (cmp(to_sort[i], pivot) < 0) {
459 UNUSED void *private_data)
477 for (i = 0; i < length; i++) result |= a[i] ^ b[i];
#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.
char * fr_trim(char const *str, size_t size)
Trim whitespace from the end of a string.
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 * fr_tolower(char *str)
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.
static int rad_lock(int fd, int lock_len, int cmd, int type)
int rad_lockfd(int fd, int lock_len)
int rad_lockfd_nonblock(int fd, int lock_len)
int fr_blocking(UNUSED int fd)
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