Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ease the reduction of the number of tests, do reduce the number of tests so that...
[simgrid.git] / include / xbt / sysdep.h
1 /* $Id$ */
2
3 /*  xbt/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                            */
6
7 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 #ifndef _XBT_SYSDEP_H
13 #define _XBT_SYSDEP_H
14
15 #include <string.h>
16 #include <stdlib.h> 
17    
18 #include "xbt/misc.h"
19 BEGIN_DECL()
20 #if 0
21 #define __CALLOC_OP(n, s)  calloc((n), (s))
22   #define __REALLOC_OP(n, s)  realloc((n), (s))
23 #define CALLOC(n, s)  ((__CALLOC_OP  ((n)?:(FAILURE("attempt to alloc 0 bytes"), 0), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory allocation error"), NULL))
24   /* #define REALLOC(p, s) ((__REALLOC_OP ((p), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory reallocation error"), NULL)) */
25   #define REALLOC(p, s) (__REALLOC_OP ((p), (s)))
26 #endif
27   
28 #define xbt_strdup(s)  ((s)?(strdup(s)?:(xbt_die("memory allocation error"),NULL))\
29                             :(NULL))
30 #define xbt_malloc(n)   (malloc(n) ?: (xbt_die("memory allocation error"),NULL))
31 #define xbt_malloc0(n)  (calloc( (n),1 ) ?: (xbt_die("memory allocation error"),NULL))
32 #define xbt_realloc(p,s) (s? (p? (realloc(p,s)?:(xbt_die("memory allocation error"),NULL)) \
33                                 : xbt_malloc(s)) \
34                             : (p? (free(p),NULL) \
35                                 : NULL))
36 #define xbt_free free /*nothing specific to do here. A poor valgrind replacement?*/
37 #define xbt_free_fct free /* replacement with the guareenty of being a function */
38    
39 #define xbt_new(type, count)  ((type*)xbt_malloc (sizeof (type) * (count)))
40 #define xbt_new0(type, count) ((type*)xbt_malloc0 (sizeof (type) * (count)))
41
42 /* Attributes are only in recent versions of GCC */
43
44 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
45 # define _XBT_GNUC_PRINTF( format_idx, arg_idx )    \
46            __attribute__((__format__ (__printf__, format_idx, arg_idx)))
47 # define _XBT_GNUC_SCANF( format_idx, arg_idx )     \
48                __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
49 # define _XBT_GNUC_FORMAT( arg_idx )                \
50                    __attribute__((__format_arg__ (arg_idx)))
51 # define _XBT_GNUC_NORETURN __attribute__((__noreturn__))
52
53 #else   /* !__GNUC__ */
54 # define _XBT_GNUC_PRINTF( format_idx, arg_idx )
55 # define _XBT_GNUC_SCANF( format_idx, arg_idx )
56 # define _XBT_GNUC_FORMAT( arg_idx )
57 # define _XBT_GNUC_NORETURN
58
59 #endif  /* !__GNUC__ */
60
61 /* inline and __FUNCTION__ are only in GCC when -ansi is off */
62
63 #if defined(__GNUC__) && ! defined(__STRICT_ANSI__)
64
65 # define _XBT_GNUC_FUNCTION __FUNCTION__
66 # define _XBT_INLINE inline
67 #else
68 # define _XBT_GNUC_FUNCTION "function"
69 # define _XBT_INLINE 
70 #endif
71
72 END_DECL()
73    
74 #include "xbt/error.h" /* needed for xbt_die */
75
76 #endif /* _XBT_SYSDEP_H */