~q3cpma/mus

ref: cf29c2237d0c99e5240a55895c07564ef4635392 mus/mus_player/misc.h -rw-r--r-- 2.2 KiB
cf29c223q3cpma Add a #pragma once to the new xoshiro128plus.h header 1 year, 7 months ago
                                                                                
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once

#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#if defined(__GNUC__) || defined(__clang__)
#define ATTR_FMT_PRINTF(fmt_index, chk_index) \
	__attribute__ ((format (printf, fmt_index, chk_index)))
#else
#define ATTR_FMT_PRINTF(fmt_index, chk_index)
#endif

#define SUN_PATH_LEN (sizeof(struct sockaddr_un) - \
		offsetof(struct sockaddr_un, sun_path))


bool isbigendian(void);

/* Return the file size of path, UINT64_MAX if an error occured during
   evaluation */
uint64_t file_size(const char *path);

/* getdelim wrapper removing the delimiter if present at the end of the line */
ssize_t getdelim_trim(char **lineptr, size_t *n, int delim, FILE *stream);

static inline ssize_t getline_trim(char **lineptr, size_t *n, FILE *stream)
{
	return getdelim_trim(lineptr, n, '\n', stream);
}

static inline uint64_t u64min(uint64_t a, uint64_t b)
{
	return a < b ? a : b;
}

/* strto* functions with error checking boilerplate taken care off (aborting
   when encountering an error) */
float xstrtof(const char *str);
long xstrtol(const char *str);
int xstrtoi(const char *str);

/* Set SA_RESTART for all signals not having term/core as default handler */
void signals_nointerrupt(void);

/* Read nbyte of fd into buf, completely. Returns false if an error occured or
   EOF was reached before reading nbyte */
bool read_full(int fd, void *buf, size_t nbyte);

/* Write nbyte of buf to fd, completely. Returns false if an error occured */
bool write_full(int fd, const void *buf, size_t nbyte);

/* -1: recv error other than ECONNRESET
	n <= len: n bytes read (n can be 0)
	len + 1: len bytes read, but buffer was too small to read everything */
ssize_t recv_full(int sockfd, void *buf, size_t len);

/* true: OK
   false: error */
bool send_full(int sockfd, void *buf, size_t len);

/* open() that aborts if an error is encountered */
int xopen(const char *path, int oflag);

/* close() that aborts if an error is encountered */
void xclose(int fd);

/* fclose() that aborts if an error is encountered */
void xfclose(FILE *stream);

/* strdup() that aborts instead of returning NULL */
void *xstrdup(const char *s);

/* malloc() that aborts instead of returning NULL */
void *xmalloc(size_t size);