LCOV - code coverage report
Current view: top level - src/libs/ease - conversion.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 37 37 100.0 %
Date: 2019-09-12 12:28:41 Functions: 25 25 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Elektra High Level API.
       5             :  *
       6             :  * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include "kdbease.h"
      10             : #include "kdbhelper.h"
      11             : #include <ctype.h>
      12             : #include <errno.h>
      13             : #include <stdint.h>
      14             : #include <stdlib.h>
      15             : #include <string.h>
      16             : 
      17             : #ifdef __cplusplus
      18             : extern "C" {
      19             : #endif
      20             : 
      21             : #define CAT(X, Y) CAT_ (X, Y)
      22             : #define CAT_(X, Y) X##Y
      23             : 
      24             : /**
      25             :  * Converts a Key to string.
      26             :  *
      27             :  * The variable pointed to by @p variable is unchanged,
      28             :  * if an error occurs.
      29             :  *
      30             :  * @param key      the key to convert
      31             :  * @param variable pointer to the output variable
      32             :  * @retval 1 on success
      33             :  * @retval 0 otherwise
      34             :  */
      35          32 : int elektraKeyToString (const Key * key ELEKTRA_UNUSED, const char ** variable ELEKTRA_UNUSED)
      36             : {
      37             : #define TYPE_NAME String
      38             : #define TYPE const char *
      39             : #define KDB_TYPE KDB_TYPE_STRING
      40             : #define PRE_CHECK_FAIL_BLOCK
      41             : #define CHECK_FAIL_BLOCK
      42             : #define TO_VALUE (string)
      43             : #define PRE_CHECK_CONVERSION (keyIsString (key) == 1)
      44             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
      45             : #define KEY_PARAM_NAME key
      46             : #define VARIABLE_PARAM_NAME variable
      47             : #define CODE_ONLY 1
      48             : 
      49             : #include "macros/type_create_to_value.h"
      50             : 
      51             : #undef KDB_TYPE
      52             : }
      53             : 
      54             : /**
      55             :  * Converts a Key to boolean.
      56             :  *
      57             :  * The value "1" is regarded as true, anything is as false.
      58             :  *
      59             :  * The variable pointed to by @p variable is unchanged,
      60             :  * if an error occurs.
      61             :  *
      62             :  * @param key      the key to convert
      63             :  * @param variable pointer to the output variable
      64             :  * @retval 1 on success
      65             :  * @retval 0 otherwise
      66             :  */
      67          26 : int elektraKeyToBoolean (const Key * key ELEKTRA_UNUSED, kdb_boolean_t * variable ELEKTRA_UNUSED)
      68             : {
      69             : #define TYPE_NAME Boolean
      70             : #define TYPE kdb_boolean_t
      71             : #define KDB_TYPE KDB_TYPE_BOOLEAN
      72             : #define PRE_CHECK_CONVERSION ((string[0] == '0' || string[0] == '1') && string[1] == '\0')
      73             : #define PRE_CHECK_FAIL_BLOCK
      74             : #define CHECK_FAIL_BLOCK
      75             : #define TO_VALUE (string[0] == '1')
      76             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
      77             : #define CODE_ONLY 1
      78             : #define KEY_PARAM_NAME key
      79             : #define VARIABLE_PARAM_NAME variable
      80             : 
      81             : #include "macros/type_create_to_value.h"
      82             : 
      83             : #undef KDB_TYPE
      84             : }
      85             : 
      86             : 
      87             : /**
      88             :  * Converts a Key to char.
      89             :  *
      90             :  * The variable pointed to by @p variable is unchanged,
      91             :  * if an error occurs.
      92             :  *
      93             :  * @param key      the key to convert
      94             :  * @param variable pointer to the output variable
      95             :  * @retval 1 on success
      96             :  * @retval 0 otherwise
      97             :  */
      98         534 : int elektraKeyToChar (const Key * key ELEKTRA_UNUSED, kdb_char_t * variable ELEKTRA_UNUSED)
      99             : {
     100             : #define TYPE_NAME Char
     101             : #define TYPE kdb_char_t
     102             : #define KDB_TYPE KDB_TYPE_CHAR
     103             : #define PRE_CHECK_FAIL_BLOCK
     104             : #define CHECK_FAIL_BLOCK
     105             : #define TO_VALUE (string[0])
     106             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     107             : #define CODE_ONLY 1
     108             : #define KEY_PARAM_NAME key
     109             : #define VARIABLE_PARAM_NAME variable
     110             : 
     111             : #include "macros/type_create_to_value.h"
     112             : 
     113             : #undef KDB_TYPE
     114             : }
     115             : 
     116             : 
     117             : /**
     118             :  * Converts a Key to octet.
     119             :  *
     120             :  * The variable pointed to by @p variable is unchanged,
     121             :  * if an error occurs.
     122             :  *
     123             :  * @param key      the key to convert
     124             :  * @param variable pointer to the output variable
     125             :  * @retval 1 on success
     126             :  * @retval 0 otherwise
     127             :  */
     128          32 : int elektraKeyToOctet (const Key * key ELEKTRA_UNUSED, kdb_octet_t * variable ELEKTRA_UNUSED)
     129             : {
     130             : #define TYPE_NAME Octet
     131             : #define TYPE kdb_octet_t
     132             : #define KDB_TYPE KDB_TYPE_OCTET
     133             : #define PRE_CHECK_BLOCK ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK
     134             : #define PRE_CHECK_CONVERSION (ELEKTRA_TYPE_NEGATIVE_PRE_CHECK)
     135             : #define PRE_CHECK_FAIL_BLOCK
     136             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= UINT8_MAX)
     137             : #define CHECK_FAIL_BLOCK
     138             : #define VALUE_TYPE unsigned long
     139             : #define TO_VALUE (strtoul (string, &end, 10))
     140             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     141             : #define CODE_ONLY 1
     142             : #define KEY_PARAM_NAME key
     143             : #define VARIABLE_PARAM_NAME variable
     144             : 
     145             : #include "macros/type_create_to_value.h"
     146             : 
     147             : #undef KDB_TYPE
     148             : }
     149             : 
     150             : 
     151             : /**
     152             :  * Converts a Key to short.
     153             :  *
     154             :  * The variable pointed to by @p variable is unchanged,
     155             :  * if an error occurs.
     156             :  *
     157             :  * @param key      the key to convert
     158             :  * @param variable pointer to the output variable
     159             :  * @retval 1 on success
     160             :  * @retval 0 otherwise
     161             :  */
     162          77 : int elektraKeyToShort (const Key * key ELEKTRA_UNUSED, kdb_short_t * variable ELEKTRA_UNUSED)
     163             : {
     164             : #define TYPE_NAME Short
     165             : #define TYPE kdb_short_t
     166             : #define KDB_TYPE KDB_TYPE_SHORT
     167             : #define PRE_CHECK_FAIL_BLOCK
     168             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= INT16_MAX && value >= INT16_MIN)
     169             : #define CHECK_FAIL_BLOCK
     170             : #define VALUE_TYPE long
     171             : #define TO_VALUE (strtol (string, &end, 10))
     172             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     173             : #define CODE_ONLY 1
     174             : #define KEY_PARAM_NAME key
     175             : #define VARIABLE_PARAM_NAME variable
     176             : 
     177             : #include "macros/type_create_to_value.h"
     178             : 
     179             : #undef KDB_TYPE
     180             : }
     181             : 
     182             : 
     183             : /**
     184             :  * Converts a Key to unsigned_short.
     185             :  *
     186             :  * The variable pointed to by @p variable is unchanged,
     187             :  * if an error occurs.
     188             :  *
     189             :  * @param key      the key to convert
     190             :  * @param variable pointer to the output variable
     191             :  * @retval 1 on success
     192             :  * @retval 0 otherwise
     193             :  */
     194          54 : int elektraKeyToUnsignedShort (const Key * key ELEKTRA_UNUSED, kdb_unsigned_short_t * variable ELEKTRA_UNUSED)
     195             : {
     196             : #define TYPE_NAME UnsignedShort
     197             : #define TYPE kdb_unsigned_short_t
     198             : #define KDB_TYPE KDB_TYPE_UNSIGNED_SHORT
     199             : #define PRE_CHECK_BLOCK ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK
     200             : #define PRE_CHECK_CONVERSION (ELEKTRA_TYPE_NEGATIVE_PRE_CHECK)
     201             : #define PRE_CHECK_FAIL_BLOCK
     202             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= UINT16_MAX)
     203             : #define CHECK_FAIL_BLOCK
     204             : #define VALUE_TYPE unsigned long
     205             : #define TO_VALUE (strtoul (string, &end, 10))
     206             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     207             : #define CODE_ONLY 1
     208             : #define KEY_PARAM_NAME key
     209             : #define VARIABLE_PARAM_NAME variable
     210             : 
     211             : #include "macros/type_create_to_value.h"
     212             : 
     213             : #undef KDB_TYPE
     214             : }
     215             : 
     216             : 
     217             : /**
     218             :  * Converts a Key to long.
     219             :  *
     220             :  * The variable pointed to by @p variable is unchanged,
     221             :  * if an error occurs.
     222             :  *
     223             :  * @param key      the key to convert
     224             :  * @param variable pointer to the output variable
     225             :  * @retval 1 on success
     226             :  * @retval 0 otherwise
     227             :  */
     228          76 : int elektraKeyToLong (const Key * key ELEKTRA_UNUSED, kdb_long_t * variable ELEKTRA_UNUSED)
     229             : {
     230             : #define TYPE_NAME Long
     231             : #define TYPE kdb_long_t
     232             : #define KDB_TYPE KDB_TYPE_LONG
     233             : #define PRE_CHECK_FAIL_BLOCK
     234             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= INT32_MAX && value >= INT32_MIN)
     235             : #define CHECK_FAIL_BLOCK
     236             : #define VALUE_TYPE long long
     237             : #define TO_VALUE (ELEKTRA_LONG_LONG_S (string, &end, 10))
     238             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     239             : #define CODE_ONLY 1
     240             : #define KEY_PARAM_NAME key
     241             : #define VARIABLE_PARAM_NAME variable
     242             : 
     243             : #include "macros/type_create_to_value.h"
     244             : 
     245             : #undef KDB_TYPE
     246             : }
     247             : 
     248             : 
     249             : /**
     250             :  * Converts a Key to unsigned_long.
     251             :  *
     252             :  * The variable pointed to by @p variable is unchanged,
     253             :  * if an error occurs.
     254             :  *
     255             :  * @param key      the key to convert
     256             :  * @param variable pointer to the output variable
     257             :  * @retval 1 on success
     258             :  * @retval 0 otherwise
     259             :  */
     260          44 : int elektraKeyToUnsignedLong (const Key * key ELEKTRA_UNUSED, kdb_unsigned_long_t * variable ELEKTRA_UNUSED)
     261             : {
     262             : #define TYPE_NAME UnsignedLong
     263             : #define TYPE kdb_unsigned_long_t
     264             : #define KDB_TYPE KDB_TYPE_UNSIGNED_LONG
     265             : #define PRE_CHECK_BLOCK ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK
     266             : #define PRE_CHECK_CONVERSION (ELEKTRA_TYPE_NEGATIVE_PRE_CHECK)
     267             : #define PRE_CHECK_FAIL_BLOCK
     268             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= UINT32_MAX)
     269             : #define CHECK_FAIL_BLOCK
     270             : #define VALUE_TYPE unsigned long long
     271             : #define TO_VALUE (ELEKTRA_UNSIGNED_LONG_LONG_S (string, &end, 10))
     272             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     273             : #define CODE_ONLY 1
     274             : #define KEY_PARAM_NAME key
     275             : #define VARIABLE_PARAM_NAME variable
     276             : 
     277             : #include "macros/type_create_to_value.h"
     278             : 
     279             : #undef KDB_TYPE
     280             : }
     281             : 
     282             : 
     283             : /**
     284             :  * Converts a Key to long_long.
     285             :  *
     286             :  * The variable pointed to by @p variable is unchanged,
     287             :  * if an error occurs.
     288             :  *
     289             :  * @param key      the key to convert
     290             :  * @param variable pointer to the output variable
     291             :  * @retval 1 on success
     292             :  * @retval 0 otherwise
     293             :  */
     294         102 : int elektraKeyToLongLong (const Key * key ELEKTRA_UNUSED, kdb_long_long_t * variable ELEKTRA_UNUSED)
     295             : {
     296             : #define TYPE_NAME LongLong
     297             : #define TYPE kdb_long_long_t
     298             : #define KDB_TYPE KDB_TYPE_LONG_LONG
     299             : #define PRE_CHECK_FAIL_BLOCK
     300             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= INT64_MAX && value >= INT64_MIN)
     301             : #define CHECK_FAIL_BLOCK
     302             : #define VALUE_TYPE long long
     303             : #define TO_VALUE (ELEKTRA_LONG_LONG_S (string, &end, 10))
     304             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     305             : #define CODE_ONLY 1
     306             : #define KEY_PARAM_NAME key
     307             : #define VARIABLE_PARAM_NAME variable
     308             : 
     309             : #include "macros/type_create_to_value.h"
     310             : 
     311             : #undef KDB_TYPE
     312             : }
     313             : 
     314             : 
     315             : /**
     316             :  * Converts a Key to unsigned_long_long.
     317             :  *
     318             :  * The variable pointed to by @p variable is unchanged,
     319             :  * if an error occurs.
     320             :  *
     321             :  * @param key      the key to convert
     322             :  * @param variable pointer to the output variable
     323             :  * @retval 1 on success
     324             :  * @retval 0 otherwise
     325             :  */
     326          50 : int elektraKeyToUnsignedLongLong (const Key * key ELEKTRA_UNUSED, kdb_unsigned_long_long_t * variable ELEKTRA_UNUSED)
     327             : {
     328             : #define TYPE_NAME UnsignedLongLong
     329             : #define TYPE kdb_unsigned_long_long_t
     330             : #define KDB_TYPE KDB_TYPE_UNSIGNED_LONG_LONG
     331             : #define PRE_CHECK_BLOCK ELEKTRA_TYPE_NEGATIVE_PRE_CHECK_BLOCK
     332             : #define PRE_CHECK_CONVERSION (ELEKTRA_TYPE_NEGATIVE_PRE_CHECK)
     333             : #define PRE_CHECK_FAIL_BLOCK
     334             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION_RANGE (value <= UINT64_MAX)
     335             : #define CHECK_FAIL_BLOCK
     336             : #define VALUE_TYPE unsigned long long
     337             : #define TO_VALUE (ELEKTRA_UNSIGNED_LONG_LONG_S (string, &end, 10))
     338             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     339             : #define CODE_ONLY 1
     340             : #define KEY_PARAM_NAME key
     341             : #define VARIABLE_PARAM_NAME variable
     342             : 
     343             : #include "macros/type_create_to_value.h"
     344             : 
     345             : #undef KDB_TYPE
     346             : }
     347             : 
     348             : 
     349             : /**
     350             :  * Converts a Key to float.
     351             :  *
     352             :  * The variable pointed to by @p variable is unchanged,
     353             :  * if an error occurs.
     354             :  *
     355             :  * @param key      the key to convert
     356             :  * @param variable pointer to the output variable
     357             :  * @retval 1 on success
     358             :  * @retval 0 otherwise
     359             :  */
     360          96 : int elektraKeyToFloat (const Key * key ELEKTRA_UNUSED, kdb_float_t * variable ELEKTRA_UNUSED)
     361             : {
     362             : #define TYPE_NAME Float
     363             : #define TYPE kdb_float_t
     364             : #define KDB_TYPE KDB_TYPE_FLOAT
     365             : #define PRE_CHECK_FAIL_BLOCK
     366             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION
     367             : #define CHECK_FAIL_BLOCK
     368             : #define TO_VALUE (strtof (string, &end))
     369             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     370             : #define CODE_ONLY 1
     371             : #define KEY_PARAM_NAME key
     372             : #define VARIABLE_PARAM_NAME variable
     373             : 
     374             : #include "macros/type_create_to_value.h"
     375             : 
     376             : #undef KDB_TYPE
     377             : }
     378             : 
     379             : 
     380             : /**
     381             :  * Converts a Key to double.
     382             :  *
     383             :  * The variable pointed to by @p variable is unchanged,
     384             :  * if an error occurs.
     385             :  *
     386             :  * @param key      the key to convert
     387             :  * @param variable pointer to the output variable
     388             :  * @retval 1 on success
     389             :  * @retval 0 otherwise
     390             :  */
     391          76 : int elektraKeyToDouble (const Key * key ELEKTRA_UNUSED, kdb_double_t * variable ELEKTRA_UNUSED)
     392             : {
     393             : #define TYPE_NAME Double
     394             : #define TYPE kdb_double_t
     395             : #define KDB_TYPE KDB_TYPE_DOUBLE
     396             : #define PRE_CHECK_FAIL_BLOCK
     397             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION
     398             : #define CHECK_FAIL_BLOCK
     399             : #define TO_VALUE (strtod (string, &end))
     400             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     401             : #define CODE_ONLY 1
     402             : #define KEY_PARAM_NAME key
     403             : #define VARIABLE_PARAM_NAME variable
     404             : 
     405             : #include "macros/type_create_to_value.h"
     406             : 
     407             : #undef KDB_TYPE
     408             : }
     409             : 
     410             : 
     411             : #ifdef ELEKTRA_HAVE_KDB_LONG_DOUBLE
     412             : 
     413             : /**
     414             :  * Converts a Key to long_double.
     415             :  *
     416             :  * The variable pointed to by @p variable is unchanged,
     417             :  * if an error occurs.
     418             :  *
     419             :  * @param key      the key to convert
     420             :  * @param variable pointer to the output variable
     421             :  * @retval 1 on success
     422             :  * @retval 0 otherwise
     423             :  */
     424          66 : int elektraKeyToLongDouble (const Key * key ELEKTRA_UNUSED, kdb_long_double_t * variable ELEKTRA_UNUSED)
     425             : {
     426             : #define TYPE_NAME LongDouble
     427             : #define TYPE kdb_long_double_t
     428             : #define KDB_TYPE KDB_TYPE_LONG_DOUBLE
     429             : #define PRE_CHECK_FAIL_BLOCK
     430             : #define CHECK_CONVERSION ELEKTRA_TYPE_CHECK_CONVERSION
     431             : #define CHECK_FAIL_BLOCK
     432             : #define TO_VALUE (strtold (string, &end))
     433             : #define NAME_MACRO(TYPE_NAME) CAT (elektraKeyTo, TYPE_NAME)
     434             : #define CODE_ONLY 1
     435             : #define KEY_PARAM_NAME key
     436             : #define VARIABLE_PARAM_NAME variable
     437             : 
     438             : #include "macros/type_create_to_value.h"
     439             : 
     440             : #undef KDB_TYPE
     441             : }
     442             : 
     443             : #endif // ELEKTRA_HAVE_KDB_LONG_DOUBLE
     444             : 
     445             : /**
     446             :  * Converts a boolean to string
     447             :  *
     448             :  * The string is allocated with elektraMalloc() and must
     449             :  * be disposed of with elektraFree().
     450             :  *
     451             :  * @param value the boolean to convert
     452             :  * @return a new string allocated with elektraMalloc, or 0 on error
     453             :  */
     454          34 : char * elektraBooleanToString (kdb_boolean_t value)
     455             : {
     456          34 :         return elektraFormat ("%s", value ? "1" : "0");
     457             : }
     458             : 
     459             : /**
     460             :  * Converts a char to string
     461             :  *
     462             :  * The string is allocated with elektraMalloc() and must
     463             :  * be disposed of with elektraFree().
     464             :  *
     465             :  * @param value the value to convert
     466             :  * @return a new string allocated with elektraMalloc, or 0 on error
     467             :  */
     468        1046 : char * elektraCharToString (kdb_char_t value)
     469             : {
     470        1046 :         return elektraFormat ("%c", value);
     471             : }
     472             : 
     473             : /**
     474             :  * Converts an octet to string
     475             :  *
     476             :  * The string is allocated with elektraMalloc() and must
     477             :  * be disposed of with elektraFree().
     478             :  *
     479             :  * @param value the value to convert
     480             :  * @return a new string allocated with elektraMalloc, or 0 on error
     481             :  */
     482          30 : char * elektraOctetToString (kdb_octet_t value)
     483             : {
     484          30 :         return elektraFormat ("%d", value);
     485             : }
     486             : 
     487             : /**
     488             :  * Converts a short to string
     489             :  *
     490             :  * The string is allocated with elektraMalloc() and must
     491             :  * be disposed of with elektraFree().
     492             :  *
     493             :  * @param value the value to convert
     494             :  * @return a new string allocated with elektraMalloc, or 0 on error
     495             :  */
     496          60 : char * elektraShortToString (kdb_short_t value)
     497             : {
     498          60 :         return elektraFormat ("%d", value);
     499             : }
     500             : 
     501             : /**
     502             :  * Converts an unsigned short to string
     503             :  *
     504             :  * The string is allocated with elektraMalloc() and must
     505             :  * be disposed of with elektraFree().
     506             :  *
     507             :  * @param value the value to convert
     508             :  * @return a new string allocated with elektraMalloc, or 0 on error
     509             :  */
     510          42 : char * elektraUnsignedShortToString (kdb_unsigned_short_t value)
     511             : {
     512          42 :         return elektraFormat ("%d", value);
     513             : }
     514             : 
     515             : /**
     516             :  * Converts a long to string
     517             :  *
     518             :  * The string is allocated with elektraMalloc() and must
     519             :  * be disposed of with elektraFree().
     520             :  *
     521             :  * @param value the value to convert
     522             :  * @return a new string allocated with elektraMalloc, or 0 on error
     523             :  */
     524          86 : char * elektraLongToString (kdb_long_t value)
     525             : {
     526          86 :         return elektraFormat (ELEKTRA_LONG_F, value);
     527             : }
     528             : 
     529             : /**
     530             :  * Converts an unsigned long to string
     531             :  *
     532             :  * The string is allocated with elektraMalloc() and must
     533             :  * be disposed of with elektraFree().
     534             :  *
     535             :  * @param value the value to convert
     536             :  * @return a new string allocated with elektraMalloc, or 0 on error
     537             :  */
     538          50 : char * elektraUnsignedLongToString (kdb_unsigned_long_t value)
     539             : {
     540          50 :         return elektraFormat (ELEKTRA_UNSIGNED_LONG_F, value);
     541             : }
     542             : 
     543             : /**
     544             :  * Converts a long long to string
     545             :  *
     546             :  * The string is allocated with elektraMalloc() and must
     547             :  * be disposed of with elektraFree().
     548             :  *
     549             :  * @param value the value to convert
     550             :  * @return a new string allocated with elektraMalloc, or 0 on error
     551             :  */
     552          72 : char * elektraLongLongToString (kdb_long_long_t value)
     553             : {
     554          72 :         return elektraFormat (ELEKTRA_LONG_LONG_F, value);
     555             : }
     556             : 
     557             : /**
     558             :  * Converts an unsigned long long to string
     559             :  *
     560             :  * The string is allocated with elektraMalloc() and must
     561             :  * be disposed of with elektraFree().
     562             :  *
     563             :  * @param value the value to convert
     564             :  * @return a new string allocated with elektraMalloc, or 0 on error
     565             :  */
     566          48 : char * elektraUnsignedLongLongToString (kdb_unsigned_long_long_t value)
     567             : {
     568          48 :         return elektraFormat (ELEKTRA_UNSIGNED_LONG_LONG_F, value);
     569             : }
     570             : 
     571             : /**
     572             :  * Converts a float to string
     573             :  *
     574             :  * The string is allocated with elektraMalloc() and must
     575             :  * be disposed of with elektraFree().
     576             :  *
     577             :  * @param value the value to convert
     578             :  * @return a new string allocated with elektraMalloc, or 0 on error
     579             :  */
     580          86 : char * elektraFloatToString (kdb_float_t value)
     581             : {
     582          86 :         return elektraFormat ("%.9g", value);
     583             : }
     584             : 
     585             : /**
     586             :  * Converts a double to string
     587             :  *
     588             :  * The string is allocated with elektraMalloc() and must
     589             :  * be disposed of with elektraFree().
     590             :  *
     591             :  * @param value the value to convert
     592             :  * @return a new string allocated with elektraMalloc, or 0 on error
     593             :  */
     594          78 : char * elektraDoubleToString (kdb_double_t value)
     595             : {
     596          78 :         return elektraFormat ("%.17g", value);
     597             : }
     598             : 
     599             : #ifdef ELEKTRA_HAVE_KDB_LONG_DOUBLE
     600             : 
     601             : /**
     602             :  * Converts a long double to string
     603             :  *
     604             :  * The string is allocated with elektraMalloc() and must
     605             :  * be disposed of with elektraFree().
     606             :  *
     607             :  * @param value the value to convert
     608             :  * @return a new string allocated with elektraMalloc, or 0 on error
     609             :  */
     610          72 : char * elektraLongDoubleToString (kdb_long_double_t value)
     611             : {
     612          72 :         return elektraFormat ("%.21Lg", value);
     613             : }
     614             : 
     615             : #endif // ELEKTRA_HAVE_KDB_LONG_DOUBLE
     616             : 
     617             : #ifdef __cplusplus
     618             : };
     619             : #endif

Generated by: LCOV version 1.13