Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c1cf657b85266cdfc8459f00b24531088ab855e5
[simgrid.git] / include / xbt / misc.h
1 /* xbt.h - Public interface to the xbt (simgrid's toolbox)                     */
2
3 /* Copyright (c) 2004-2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef XBT_MISC_H
10 #define XBT_MISC_H
11
12 #include <stdarg.h>
13
14 #include "simgrid_config.h"
15 #include "base.h"
16 #include "dynar.h"
17
18 SG_BEGIN_DECL()
19
20 /** Cache the size of a memory page for the current system. */
21 XBT_PUBLIC_DATA(int) xbt_pagesize;
22
23 /** Cache the number of bits of addresses inside a given page, log2(xbt_pagesize). */
24 XBT_PUBLIC_DATA(int) xbt_pagebits;
25
26 XBT_PUBLIC(const char *) xbt_procname(void);
27
28 /** Retrieves the version numbers of the used dynamic library (so, DLL or dynlib) , while
29     SIMGRID_VERSION_MAJOR and friends give the version numbers of the used header files */
30 XBT_PUBLIC(void) sg_version(int *major,int *minor,int *patch);
31
32 /** Helps ensuring that the header version (SIMGRID_VERSION_MAJOR and friends) and the dynamic library version do match. */
33 XBT_PUBLIC(void) sg_version_check(int lib_version_major,int lib_version_minor,int lib_version_patch);
34
35 /** Contains all the parameters we got from the command line */
36 XBT_PUBLIC_DATA(xbt_dynar_t) sg_cmdline;
37
38 #define XBT_BACKTRACE_SIZE 10   /* FIXME: better place? Do document */
39
40 /* snprintf related functions */
41 /** @addtogroup XBT_str
42   * @{ */
43 /** @brief print to allocated string (reimplemented when not provided by the system)
44  *
45  * The functions asprintf() and vasprintf() are analogues of
46  * sprintf() and vsprintf(), except that they allocate a string large
47  * enough to hold the output including the terminating null byte, and
48  * return a pointer to it via the first parameter.  This pointer
49  * should be passed to free(3) to release the allocated storage when
50  * it is no longer needed.
51  */
52 #if defined(SIMGRID_NEED_ASPRINTF)||defined(DOXYGEN)
53 XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt,   /*args */
54                          ...) _XBT_GNUC_PRINTF(2, 3);
55 #endif
56 /** @brief print to allocated string (reimplemented when not provided by the system)
57  *
58  * See asprintf()
59  */
60 #if defined(SIMGRID_NEED_VASPRINTF)||defined(DOXYGEN)
61 XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap);
62 #endif
63
64 /** @brief print to allocated string
65  *
66  * Works just like vasprintf(), but returns a pointer to the newly
67  * created string, or aborts on error.
68  */
69 XBT_PUBLIC(char *) bvprintf(const char *fmt, va_list ap);
70 /** @brief print to allocated string
71  *
72  * Works just like asprintf(), but returns a pointer to the newly
73  * created string, or aborts on error.
74  */
75 XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2);
76 /** @} */
77
78 SG_END_DECL()
79
80 #endif                          /* XBT_MISC_H */