3 /* gras/sysdep.h -- all system dependency */
4 /* no system header should be loaded out of this file so that we have only */
5 /* one file to check when porting to another OS */
7 /* Authors: Martin Quinson */
8 /* Copyright (C) 2004 the OURAGAN project. */
10 /* This program is free software; you can redistribute it and/or modify it
11 under the terms of the license (GNU LGPL) which comes with this package. */
14 #ifndef _GRAS_SYSDEP_H
15 #define _GRAS_SYSDEP_H
17 #include <string.h> /* Included directly for speed */
19 #include <time.h> /* FIXME: remove */
20 #include <unistd.h> /* FIXME: remove */
26 char* gras_strdup (const char *str);
27 void* gras_malloc (long int bytes);
28 void* gras_malloc0 (long int bytes);
29 void* gras_realloc (void *memory, long int bytes);
30 void gras_free (void *memory);
32 #define gras_new(type, count) ((type*)gras_malloc (sizeof (type) * (count)))
33 #define gras_new0(type, count) ((type*)gras_malloc0 (sizeof (type) * (count)))
35 /* Attributes are only in recent versions of GCC */
37 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
38 # define _GRAS_GNUC_PRINTF( format_idx, arg_idx ) \
39 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
40 # define _GRAS_GNUC_SCANF( format_idx, arg_idx ) \
41 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
42 # define _GRAS_GNUC_FORMAT( arg_idx ) \
43 __attribute__((__format_arg__ (arg_idx)))
44 # define _GRAS_GNUC_NORETURN __attribute__((__noreturn__))
47 # define _GRAS_GNUC_PRINTF( format_idx, arg_idx )
48 # define _GRAS_GNUC_SCANF( format_idx, arg_idx )
49 # define _GRAS_GNUC_FORMAT( arg_idx )
50 # define _GRAS_GNUC_NORETURN
52 #endif /* !__GNUC__ */
54 /* inline and __FUNCTION__ are only in GCC when -ansi is of */
56 #if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
58 # define _GRAS_GNUC_FUNCTION __FUNCTION__
59 # define _GRAS_INLINE inline
61 # define _GRAS_GNUC_FUNCTION "function"
66 void gras_abort(void) _GRAS_GNUC_NORETURN;
68 /* FIXME: This is a very good candidate to rewrite (along with a proper string stuff)
69 but I'm too lazy right now, so copy the definition */
70 long int strtol(const char *nptr, char **endptr, int base);
71 double strtod(const char *nptr, char **endptr);
72 int atoi(const char *nptr);
80 #endif /* _GRAS_SYSDEP_H */