Skip to content
Snippets Groups Projects
Commit e4f27335 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add functions for reading/getting/settings 64-bit ints/uints

No immediate use, but I thought I had one. I didn't. Still, will probably need these one day.
parent d1e32893
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -736,6 +736,15 @@ char* iniSetHexInt(str_list_t* list, const char* section, const char* key, uint
return iniSetString(list, section, key, str, style);
}
char* iniSetHexInt64(str_list_t* list, const char* section, const char* key, uint64_t value
,ini_style_t* style)
{
char str[INI_MAX_VALUE_LEN];
SAFEPRINTF(str,"0x%" PRIx64, value);
return iniSetString(list, section, key, str, style);
}
char* iniSetFloat(str_list_t* list, const char* section, const char* key, double value
,ini_style_t* style)
{
......@@ -1646,6 +1655,22 @@ static ulong parseULongInteger(const char* value)
return(strtoul(value,NULL,0));
}
static int64_t parseInt64(const char* value)
{
if(isTrue(value))
return TRUE;
return strtoll(value,NULL,0);
}
static uint64_t parseUInt64(const char* value)
{
if(isTrue(value))
return TRUE;
return strtoull(value,NULL,0);
}
static BOOL parseBool(const char* value)
{
return(INT_TO_BOOL(parseInteger(value)));
......@@ -1792,6 +1817,58 @@ ulong iniGetULongInt(str_list_t list, const char* section, const char* key, ulon
return(parseULongInteger(vp));
}
int64_t iniReadInt64(FILE* fp, const char* section, const char* key, int64_t deflt)
{
char* value;
char buf[INI_MAX_VALUE_LEN];
if((value=read_value(fp,section,key,buf, /* literals_supported: */FALSE))==NULL)
return deflt;
if(*value==0) /* blank value */
return deflt;
return parseInt64(value);
}
uint64_t iniReadUInt64(FILE* fp, const char* section, const char* key, uint64_t deflt)
{
char* value;
char buf[INI_MAX_VALUE_LEN];
if((value=read_value(fp,section,key,buf, /* literals_supported: */FALSE))==NULL)
return deflt;
if(*value==0) /* blank value */
return deflt;
return parseUInt64(value);
}
int64_t iniGetInt64(str_list_t list, const char* section, const char* key, int64_t deflt)
{
char* vp=NULL;
get_value(list, section, key, NULL, &vp, /* literals_supported: */FALSE);
if(vp==NULL || *vp==0) /* blank value or missing key */
return deflt;
return parseInt64(vp);
}
uint64_t iniGetUInt64(str_list_t list, const char* section, const char* key, uint64_t deflt)
{
char* vp=NULL;
get_value(list, section, key, NULL, &vp, /* literals_supported: */FALSE);
if(vp==NULL || *vp==0) /* blank value or missing key */
return deflt;
return parseUInt64(vp);
}
int64_t iniReadBytes(FILE* fp, const char* section, const char* key, uint unit, int64_t deflt)
{
char* value;
......
......@@ -89,6 +89,10 @@ DLLEXPORT long iniReadLongInt(FILE*, const char* section, const char* key
,long deflt);
DLLEXPORT ulong iniReadULongInt(FILE*, const char* section, const char* key
,ulong deflt);
DLLEXPORT int64_t iniReadInt64(FILE*, const char* section, const char* key
,int64_t deflt);
DLLEXPORT uint64_t iniReadUInt64(FILE*, const char* section, const char* key
,uint64_t deflt);
DLLEXPORT int64_t iniReadBytes(FILE*, const char* section, const char* key
,uint unit, int64_t deflt);
DLLEXPORT double iniReadDuration(FILE*, const char* section, const char* key
......@@ -164,6 +168,10 @@ DLLEXPORT long iniGetLongInt(str_list_t, const char* section, const char* key
,long deflt);
DLLEXPORT ulong iniGetULongInt(str_list_t, const char* section, const char* key
,ulong deflt);
DLLEXPORT int64_t iniGetInt64(str_list_t, const char* section, const char* key
,int64_t deflt);
DLLEXPORT uint64_t iniGetUInt64(str_list_t, const char* section, const char* key
,uint64_t deflt);
DLLEXPORT int64_t iniGetBytes(str_list_t, const char* section, const char* key
,uint unit, int64_t deflt);
DLLEXPORT double iniGetDuration(str_list_t, const char* section, const char* key
......@@ -237,6 +245,8 @@ DLLEXPORT char* iniSetDuration(str_list_t*, const char* section, const char* k
,ini_style_t*);
DLLEXPORT char* iniSetHexInt(str_list_t*, const char* section, const char* key, uint value
,ini_style_t*);
DLLEXPORT char* iniSetHexInt64(str_list_t*, const char* section, const char* key, uint64_t value
,ini_style_t*);
DLLEXPORT char* iniSetFloat(str_list_t*, const char* section, const char* key, double value
,ini_style_t*);
DLLEXPORT char* iniSetBool(str_list_t*, const char* section, const char* key, BOOL value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment