summary refs log tree commit diff
path: root/misc/subr.h
blob: 9260ed90f65d8e52fd26207bb7fdcf871bedd2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef BTPD_SUBR_H
#define BTPD_SUBR_H

#include <stdio.h>
#include <stdarg.h>

#define min(x, y) ((x) <= (y) ? (x) : (y))

int set_nonblocking(int fd);
int set_blocking(int fd);

int mkdirs(char *path);

int vaopen(int *resfd, int flags, const char *fmt, va_list ap);
int vopen(int *resfd, int flags, const char *fmt, ...);
int vfopen(FILE **ret, const char *mode, const char *fmt, ...);
int vfsync(const char *fmt, ...);

void set_bit(uint8_t *bits, unsigned long index);
int has_bit(const uint8_t *bits, unsigned long index);
void clear_bit(uint8_t *bits, unsigned long index);

long rand_between(long min, long max);

int read_fully(int fd, void *buf, size_t len);
int write_fully(int fd, const void *buf, size_t len);

char *find_btpd_dir(void);

#endif