From bb919b3646c93993be19750513fc374a131a24bc Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Jan 2003 16:33:54 +0200 Subject: Changed my_strntoxxx functions to clear error number on start Allow one to change ANSI_QUOTES mode per thread and on the fly sql/field.cc: Use new my_strntoxxx functions where function clears errno. Change variable names to 'not_used' for variables that is not used in function sql/sql_base.cc: comment sql/sql_lex.cc: Allow one to change ANSI_QUOTES mode per thread and on the fly sql/sql_lex.h: Allow one to change ANSI_QUOTES mode per thread and on the fly strings/ctype-simple.c: Changed my_strntoxxx functions to clear error number on start Changed my_strtod() to correctly set return error number strings/ctype-utf8.c: Changed my_strntoxxx functions to clear error number on start Changed my_strtod() to correctly set return error number --- strings/ctype-simple.c | 26 ++++++++++++++++++-------- strings/ctype-utf8.c | 26 +++++++++++++++++++------- 2 files changed, 37 insertions(+), 15 deletions(-) (limited to 'strings') diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index df1609c983d..b47a15d2cfa 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -214,6 +214,7 @@ long my_strntol_8bit(CHARSET_INFO *cs, const char *save, *e; int overflow; + *err= 0; /* Initialize error indicator */ if (base < 0 || base == 1 || base > 36) base = 10; @@ -330,6 +331,7 @@ ulong my_strntoul_8bit(CHARSET_INFO *cs, const char *save, *e; int overflow; + *err= 0; /* Initialize error indicator */ if (base < 0 || base == 1 || base > 36) base = 10; @@ -437,6 +439,7 @@ longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)), const char *save; int overflow; + *err= 0; /* Initialize error indicator */ if (base < 0 || base == 1 || base > 36) base = 10; @@ -553,6 +556,7 @@ ulonglong my_strntoull_8bit(CHARSET_INFO *cs, const char *save; int overflow; + *err= 0; /* Initialize error indicator */ if (base < 0 || base == 1 || base > 36) base = 10; @@ -655,7 +659,8 @@ noconv: cs Character set information str String to convert to double length Optional length for string. - end pointer to end of converted string + end result pointer to end of converted string + err Error number if failed conversion NOTES: If length is not INT_MAX32 or str[length] != 0 then the given str must @@ -665,23 +670,28 @@ noconv: It's implemented this way to save a buffer allocation and a memory copy. RETURN - value of number in string + Value of number in string */ double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)), char *str, uint length, - char **end, int *err __attribute__ ((unused))) + char **end, int *err) { char end_char; double result; + errno= 0; /* Safety */ if (length == INT_MAX32 || str[length] == 0) - return strtod(str, end); - end_char= str[length]; - str[length]= 0; - result= strtod(str, end); - str[length]= end_char; /* Restore end char */ + result= strtod(str, end); + else + { + end_char= str[length]; + str[length]= 0; + result= strtod(str, end); + str[length]= end_char; /* Restore end char */ + } + *err= errno; return result; } diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index e57f35bab19..b247075622e 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -2459,7 +2459,9 @@ long my_strntol_ucs2(CHARSET_INFO *cs, register const char *e=nptr+l; const char *save; - do { + *err= 0; + do + { if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) { switch (wc) @@ -2570,7 +2572,9 @@ ulong my_strntoul_ucs2(CHARSET_INFO *cs, register const char *e=nptr+l; const char *save; - do { + *err= 0; + do + { if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) { switch (wc) @@ -2675,7 +2679,9 @@ longlong my_strntoll_ucs2(CHARSET_INFO *cs, register const char *e=nptr+l; const char *save; - do { + *err= 0; + do + { if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) { switch (wc) @@ -2788,7 +2794,9 @@ ulonglong my_strntoull_ucs2(CHARSET_INFO *cs, register const char *e=nptr+l; const char *save; - do { + *err= 0; + do + { if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) { switch (wc) @@ -2821,7 +2829,8 @@ bs: cutoff = (~(ulonglong) 0) / (unsigned long int) base; cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base); - do { + do + { if ((cnv=cs->mb_wc(cs,&wc,s,e))>0) { s+=cnv; @@ -2878,7 +2887,7 @@ bs: double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), char *nptr, uint length, - char **endptr, int *err __attribute__ ((unused))) + char **endptr, int *err) { char buf[256]; double res; @@ -2887,7 +2896,8 @@ double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), register const char *end; my_wc_t wc; int cnv; - + + *err= 0; /* Cut too long strings */ if (length >= sizeof(buf)) length= sizeof(buf)-1; @@ -2902,7 +2912,9 @@ double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), } *b= 0; + errno= 0; res=strtod(buf, endptr); + *err= errno; if (endptr) *endptr=(char*) (*endptr-buf+nptr); return res; -- cgit v1.2.1