examples: warn on invalid numeric parameters

add ExUtilGet[U]Int / ExUtilGetFloat which print an error message on
parse failure.
fixes issue #219.

Change-Id: Ie537f5aebd138925bf1a48289b6b5e261b3af2ca
This commit is contained in:
James Zern
2014-09-10 23:35:48 -07:00
parent be70b86c57
commit 96d43a873a
7 changed files with 114 additions and 41 deletions

View File

@ -20,6 +20,19 @@
extern "C" {
#endif
//------------------------------------------------------------------------------
// String parsing
// Parses 'v' using strto(ul|l|d)(). If error is non-NULL, '*error' is set to
// true on failure while on success it is left unmodified to allow chaining of
// calls. An error is only printed on the first occurrence.
uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
int ExUtilGetInt(const char* const v, int base, int* const error);
float ExUtilGetFloat(const char* const v, int* const error);
//------------------------------------------------------------------------------
// File I/O
// Reopen file in binary (O_BINARY) mode.
// Returns 'file' on success, NULL otherwise.
FILE* ExUtilSetBinaryMode(FILE* file);