diff --git a/ChangeLog b/ChangeLog index b16a5946e7..355117e71c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ 2001-06-01 Dave Peticolas + * src/engine/sixtp-dom-parsers.c (string_to_integer): use new + scanf macro below + + * src/engine/sixtp-utils.c: use new scanf macro below + + * src/engine/gnc-numeric.c: use new scanf macro below + + * src/engine/gnc-engine-util.h: define GNC_SCANF_LLD macro to use + for scanf long long int conversion. This is needed since there is + not a common solution between Linux, Solaris, and FreeBSD. Thanks + to Matthew Condell for finding the problem and to Matt and Alan + Orndorff for testing it. + + * configure.in: invoke conversion test below + + * acinclude.m4: add test for %lld scanf conversion + * README: update info 2001-06-01 Robert Graham Merkel diff --git a/acinclude.m4 b/acinclude.m4 index 088a6875a1..4157666055 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -279,10 +279,13 @@ AC_DEFUN([LANGINFO_D_FMT_CHECK], AC_DEFUN([STRUCT_TM_GMTOFF_CHECK], [ - AC_CACHE_CHECK([for the tm_gmtoff member of struct tm], am_cv_struct_tm_gmtoff, - [AC_TRY_LINK([#include - #define _GNU_SOURCE - #define __EXTENSIONS__], + AC_CACHE_CHECK([for the tm_gmtoff member of struct tm], + am_cv_struct_tm_gmtoff, + [AC_TRY_LINK([ + #include + #define _GNU_SOURCE + #define __EXTENSIONS__ +], [struct tm tm; tm.tm_gmtoff = 0;], am_cv_struct_tm_gmtoff=yes, @@ -293,3 +296,30 @@ AC_DEFUN([STRUCT_TM_GMTOFF_CHECK], [Define if you have the tm_gmtoff member of struct tm.]) fi ]) + +AC_DEFUN([SCANF_LLD_CHECK], +[ + AC_CACHE_CHECK([if scanf supports %lld conversions], + am_cv_scanf_lld, + AC_TRY_RUN([ +#include +#include + +int main () +{ + long long int d; + + d = 0; + if ((sscanf ("10000000000", "%lld", &d) != 1) || (d != 10000000000)) + exit (1); + + exit (0); +} +], + am_cv_scanf_lld=yes, + am_cv_scanf_lld=no)) + if test $am_cv_scanf_lld = yes; then + AC_DEFINE(HAVE_SCANF_LLD, 1, + [Define if scanf supports %lld conversions.]) + fi +]) diff --git a/configure.in b/configure.in index 93552378dc..745c687910 100644 --- a/configure.in +++ b/configure.in @@ -46,6 +46,7 @@ AC_CHECK_HEADERS(limits.h) AC_CHECK_FUNCS(stpcpy memcpy timegm) STRUCT_TM_GMTOFF_CHECK +SCANF_LLD_CHECK AM_PATH_GLIB diff --git a/src/engine/gnc-engine-util.h b/src/engine/gnc-engine-util.h index 165870a6ba..4a06041204 100644 --- a/src/engine/gnc-engine-util.h +++ b/src/engine/gnc-engine-util.h @@ -169,6 +169,13 @@ void gnc_set_log_level_global(gncLogLevel level); } \ } +/* Define the long long int conversion for scanf */ +#if HAVE_SCANF_LLD +# define GNC_SCANF_LLD "%lld" +#else +# define GNC_SCANF_LLD "%qd" +#endif + /** Prototypes *************************************************/ diff --git a/src/engine/gnc-numeric.c b/src/engine/gnc-numeric.c index 1a787881cf..c022b05058 100644 --- a/src/engine/gnc-numeric.c +++ b/src/engine/gnc-numeric.c @@ -1062,7 +1062,8 @@ string_to_gnc_numeric(const gchar* str, gnc_numeric *n) { if(!str) return NULL; /* must use "<" here because %n's effects aren't well defined */ - if(sscanf(str, " %lld/%lld%n", &tmpnum, &tmpdenom, &num_read) < 2) { + if(sscanf(str, " " GNC_SCANF_LLD "/" GNC_SCANF_LLD "%n", + &tmpnum, &tmpdenom, &num_read) < 2) { return(NULL); } n->num = tmpnum; diff --git a/src/engine/sixtp-dom-parsers.c b/src/engine/sixtp-dom-parsers.c index a28a3420da..29b77d3769 100644 --- a/src/engine/sixtp-dom-parsers.c +++ b/src/engine/sixtp-dom-parsers.c @@ -742,7 +742,7 @@ string_to_integer(const char *content, gint64 *to) { long long int to_in; - if(sscanf(content, "%lld", &to_in) == 1) + if(sscanf(content, GNC_SCANF_LLD, &to_in) == 1) { if (to) *to = to_in; diff --git a/src/engine/sixtp-utils.c b/src/engine/sixtp-utils.c index 1ca1f1498b..f9f7e436d8 100644 --- a/src/engine/sixtp-utils.c +++ b/src/engine/sixtp-utils.c @@ -39,6 +39,8 @@ #include "date.h" #include "guid.h" #include "gnc-numeric.h" +#include "gnc-engine-util.h" + gboolean isspace_str(const gchar *str, int nomorethan) { @@ -197,7 +199,7 @@ string_to_gint64(const gchar *str, gint64 *v) { int num_read; /* must use "<" here because %n's effects aren't well defined */ - if(sscanf(str, " %lld %n", &v_in, &num_read) < 1) { + if(sscanf(str, " " GNC_SCANF_LLD " %n", &v_in, &num_read) < 1) { return(FALSE); } diff --git a/src/gnc-ui-util.c b/src/gnc-ui-util.c index cf02ed0d29..c2d6eabf28 100644 --- a/src/gnc-ui-util.c +++ b/src/gnc-ui-util.c @@ -1679,7 +1679,7 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result, { *out = '\0'; - if (*out_str != '\0' && sscanf(out_str, "%lld", &numer) < 1) + if (*out_str != '\0' && sscanf(out_str, GNC_SCANF_LLD, &numer) < 1) { next_state = NO_NUM_ST; } @@ -1775,7 +1775,7 @@ xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result, len = 8; } - if (sscanf (out_str, "%lld", &fraction) < 1) + if (sscanf (out_str, GNC_SCANF_LLD, &fraction) < 1) { g_free(out_str); return FALSE;