Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2575bf97fb4e69df1f064c6a8519ac9d14f50a6d
[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 "gras_private.h"
14
15 #include <stdlib.h>
16
17 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, gros, "System dependency");
18
19 /****
20  **** Memory management
21  ****/
22
23 void* gras_malloc  (long int bytes) {
24    void *ptr = (bytes == 0 ? NULL : (void*) malloc ((size_t) bytes));
25    gras_assert1(ptr, "Malloc of %ld bytes failed",bytes);
26    return ptr;
27 }
28 void* gras_malloc0 (long int bytes) {
29    void *ptr = (bytes == 0 ? NULL : (void*) calloc ((size_t) bytes, 1));
30    gras_assert1(ptr, "Malloc of %ld bytes failed",bytes);
31    return ptr;
32 }
33
34 void* gras_realloc (void  *memory, long int bytes) {
35    if (bytes == 0) {
36       gras_free(memory);
37       return NULL;
38    } else {
39       void *ptr = (void*) realloc (memory, (size_t) bytes);
40       gras_assert1(ptr, "Realloc of %ld bytes failed",bytes);
41       return ptr;
42    }
43 }
44 char* gras_strdup  (const char* str) {
45    char *ret = (char*)strdup(str);
46    gras_assert0(ret, "String duplication failed");
47    return ret;
48 }
49
50 void  gras_free (void  *memory) {
51    if (memory)
52      free (memory);
53 }
54
55 /****
56  **** Misc
57  ****/
58
59 void gras_abort(void) {
60    abort();
61 }