X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3d0d626e19a7b79320e7d922c9c1dcf122076cea..48fb61a024cd614fd1544b95c360022fc470b505:/src/xbt/sysdep.c diff --git a/src/xbt/sysdep.c b/src/xbt/sysdep.c index 2575bf97fb..428d006728 100644 --- a/src/xbt/sysdep.c +++ b/src/xbt/sysdep.c @@ -1,61 +1,37 @@ /* $Id$ */ -/* gras/sysdep.h -- all system dependency */ +/* sysdep.c -- all system dependency */ /* no system header should be loaded out of this file so that we have only */ /* one file to check when porting to another OS */ -/* Authors: Martin Quinson */ -/* Copyright (C) 2004 the OURAGAN project. */ +/* Copyright (c) 2004 Martin Quinson. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "gras_private.h" +#include "xbt/sysdep.h" +#include "xbt/log.h" +#include "xbt/error.h" +#include "portable.h" -#include +/* \defgroup XBT_sysdep All system dependency + * \brief This section describes many macros/functions that can serve as + * an OS abstraction. + */ -GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, gros, "System dependency"); +double xbt_os_time(void) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; -/**** - **** Memory management - ****/ + gettimeofday(&tv, NULL); -void* gras_malloc (long int bytes) { - void *ptr = (bytes == 0 ? NULL : (void*) malloc ((size_t) bytes)); - gras_assert1(ptr, "Malloc of %ld bytes failed",bytes); - return ptr; -} -void* gras_malloc0 (long int bytes) { - void *ptr = (bytes == 0 ? NULL : (void*) calloc ((size_t) bytes, 1)); - gras_assert1(ptr, "Malloc of %ld bytes failed",bytes); - return ptr; -} - -void* gras_realloc (void *memory, long int bytes) { - if (bytes == 0) { - gras_free(memory); - return NULL; - } else { - void *ptr = (void*) realloc (memory, (size_t) bytes); - gras_assert1(ptr, "Realloc of %ld bytes failed",bytes); - return ptr; - } -} -char* gras_strdup (const char* str) { - char *ret = (char*)strdup(str); - gras_assert0(ret, "String duplication failed"); - return ret; + return (double)(tv.tv_sec + tv.tv_usec / 1000000.0); +#else + /* Poor resolution */ + return (double)(time(NULL)); +#endif /* HAVE_GETTIMEOFDAY? */ } -void gras_free (void *memory) { - if (memory) - free (memory); -} -/**** - **** Misc - ****/ +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency"); -void gras_abort(void) { - abort(); -}