Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f7408972e7a346d849541b4718c7b5742d471630
[simgrid.git] / src / xbt / sysdep.c
1 /* $Id$ */
2
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                            */
6
7 /* Authors: Martin Quinson                                                  */
8 /* Copyright (C) 2004 the OURAGAN project.                                  */
9
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. */
12
13 #include "xbt/sysdep.h"
14 #include "xbt/log.h"
15 #include "xbt/error.h"
16
17 #include <stdlib.h>
18
19 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency");
20
21 /****
22  **** Memory management
23  ****/
24
25 void* gras_malloc  (long int bytes) {
26    void *ptr = (bytes == 0 ? NULL : (void*) malloc ((size_t) bytes));
27    gras_assert1(ptr, "Malloc of %ld bytes failed",bytes);
28    return ptr;
29 }
30 void* gras_malloc0 (long int bytes) {
31    void *ptr = (bytes == 0 ? NULL : (void*) calloc ((size_t) bytes, 1));
32    gras_assert1(ptr, "Malloc of %ld bytes failed",bytes);
33    return ptr;
34 }
35
36 void* gras_realloc (void  *memory, long int bytes) {
37    if (bytes == 0) {
38       gras_free(memory);
39       return NULL;
40    } else {
41       void *ptr = (void*) realloc (memory, (size_t) bytes);
42       gras_assert1(ptr, "Realloc of %ld bytes failed",bytes);
43       return ptr;
44    }
45 }
46 char* gras_strdup  (const char* str) {
47    char *ret = (char*)strdup(str);
48    gras_assert0(ret, "String duplication failed");
49    return ret;
50 }
51
52 void  gras_free (void  *memory) {
53    if (memory)
54      free (memory);
55 }
56
57 /****
58  **** Misc
59  ****/
60
61 void gras_abort(void) {
62    abort();
63 }