share/common.h: add illusion of sanity
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 24 Jan 2011 10:43:18 +0000 (10:43 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 24 Jan 2011 10:43:18 +0000 (10:43 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3461 78b8d119-cf0a-0410-b17c-f493084dd1d7

share/common.h

index 9d2b8c1..e9a24e7 100644 (file)
 #include <stdio.h>
 #include "fs.h"
 
+/* Random stuff. */
+
 #ifdef __GNUC__
 #define NULL_TERMINATED __attribute__ ((__sentinel__))
 #else
 #define NULL_TERMINATED
 #endif
 
-#define ARRAYSIZE(a) (sizeof (a) / sizeof ((a)[0]))
-#define MAXSTRLEN(a) (sizeof (a) - 1)
+/* Math. */
 
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 #define MAX(x, y) ((x) > (y) ? (x) : (y))
 
-#define SAFECPY(dst, src) (strncpy((dst), (src), MAXSTRLEN(dst)))
-#define SAFECAT(dst, src) (strncat((dst), \
-                                   (src), \
-                                   MAX(0, MAXSTRLEN(dst) - strlen(dst))))
-
 #define SIGN(n) ((n) < 0 ? -1 : ((n) ? +1 : 0))
 #define ROUND(f) ((int) ((f) + 0.5f * SIGN(f)))
 
 #define TIME_TO_MS(t) ROUND((t) * 1000.0f)
 #define MS_TO_TIME(m) ((m) * 0.001f)
 
+int rand_between(int low, int high);
+
+/* Arrays and strings. */
+
+#define ARRAYSIZE(a) (sizeof (a) / sizeof ((a)[0]))
+#define MAXSTRLEN(a) (sizeof (a) - 1)
+
+#define SAFECPY(dst, src) (strncpy((dst), (src), MAXSTRLEN(dst)))
+#define SAFECAT(dst, src) (strncat((dst), \
+                                   (src), \
+                                   MAX(0, MAXSTRLEN(dst) - strlen(dst))))
+
 int   read_line(char **, fs_file);
 char *strip_newline(char *);
 
@@ -61,13 +69,19 @@ char *concat_string(const char *first, ...) NULL_TERMINATED;
 #define str_starts_with(s, h) (strncmp((s), (h), strlen(h)) == 0)
 #define str_ends_with(s, t) (strcmp((s) + strlen(s) - strlen(t), (t)) == 0)
 
+/* Time. */
+
 time_t make_time_from_utc(struct tm *);
 const char *date_to_str(time_t);
 
+/* Files. */
+
 int  file_exists(const char *);
 int  file_rename(const char *, const char *);
 void file_copy(FILE *fin, FILE *fout);
 
+/* Paths. */
+
 int path_is_sep(int);
 int path_is_abs(const char *);
 
@@ -80,6 +94,4 @@ const char *base_name(const char *name);
 const char *base_name_sans(const char *name, const char *suffix);
 const char *dir_name(const char *name);
 
-int rand_between(int low, int high);
-
 #endif