Make user responsible for allocating `struct bitmap's.
[pintos-anon] / src / lib / lib.h
1 #ifndef HEADER_LIB_H
2 #define HEADER_LIB_H 1
3
4 #include <stdarg.h>
5 #include <stddef.h>
6 #include "debug.h"
7
8 #define ROUND_UP(X, STEP) (((X) + (STEP) - 1) / (STEP) * (STEP))
9 #define DIV_ROUND_UP(X, STEP) (((X) + (STEP) - 1) / (STEP))
10 #define ROUND_DOWN(X, STEP) ((X) / (STEP) * (STEP))
11
12 void *memset (void *, int, size_t);
13 void *memcpy (void *, const void *, size_t);
14 void *memmove (void *, const void *, size_t);
15 void *memchr (const void *, int, size_t);
16 int memcmp (const void *, const void *, size_t);
17
18 char *strchr (const char *, int);
19 size_t strlcpy (char *, const char *, size_t);
20 size_t strlen (const char *);
21
22 void vprintk (const char *, va_list);
23 void printk (const char *, ...) PRINTF_FORMAT (1, 2);
24 int vsnprintf (char *, size_t, const char *, va_list);
25 int snprintf (char *, size_t, const char *, ...) PRINTF_FORMAT (3, 4);
26
27 void hex_dump (const void *, size_t size);
28
29 static inline int isdigit (int c) { return c >= '0' && c <= '9'; }
30 static inline int isprint (int c) { return c >= 32 && c < 127; }
31 static inline int isgraph (int c) { return c >= 33 && c < 127; }
32 static inline int isspace (int c) { return strchr (" \t\n\r\v", c) != NULL; }
33 static inline int islower (int c) { return c >= 'a' && c <= 'z'; }
34 static inline int isupper (int c) { return c >= 'A' && c <= 'Z'; }
35 static inline int isalpha (int c) { return islower (c) || isupper (c); }
36
37 #endif /* lib.h */