-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathind.h
41 lines (33 loc) · 1.09 KB
/
ind.h
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
/*
* Copy me if you can.
* by 20h
* some additions by lazr
*/
#ifndef __IND_H__
#define __IND_H__
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
/* A collection of useful utility functions that honestly should be in
* the standard library anyways.
*/
// Error functions
void die(char *fmt, ...);
void edie(char *fmt, ...);
// Memory functions
void *reallocz(void *p, const size_t l, const int z);
void *mallocz(const size_t l, int z);
void *memdup(void *p, const size_t l);
void *memdupz(const void *p, const size_t l);
void *memdupcat(void *p, const size_t lp, void *c, const size_t lc);
// String functions
char *vsmprintf(char *fmt, va_list fmtargs, const size_t size);
char *smprintf(char *fmt, ...);
char *readtoeoffd(int fd, int *len);
char *freadall(FILE *f, int *len);
char *sgets(char *s, const size_t size, char **p);
// Use this for getting a container type from a pointer to an element
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif