diff options
Diffstat (limited to 'mysys/mf_iocache2.c')
-rw-r--r-- | mysys/mf_iocache2.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index 7a40ea8a86f..04a5214e2d4 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -429,9 +429,9 @@ process_flags: /* minimum width padding */ if (minimum_width > length2) { - char *buffz; + uchar *buffz; - buffz= my_alloca(minimum_width - length2); + buffz= (uchar*) my_alloca(minimum_width - length2); if (is_zero_padded) memset(buffz, '0', minimum_width - length2); else @@ -473,3 +473,53 @@ process_flags: err: return (size_t) -1; } + + +int init_strvar_from_file(char *var, int max_size, IO_CACHE *f, + const char *default_val) +{ + uint length; + DBUG_ENTER("init_strvar_from_file"); + + if ((length=my_b_gets(f,var, max_size))) + { + char* last_p = var + length -1; + if (*last_p == '\n') + *last_p = 0; /* if we stopped on newline, kill it */ + else + { + /* + If we truncated a line or stopped on last char, remove all chars + up to and including newline. + */ + int c; + while (((c=my_b_get(f)) != '\n' && c != my_b_EOF)) + ; + } + DBUG_RETURN(0); + } + else if (default_val) + { + strmake(var, default_val, max_size-1); + DBUG_RETURN(0); + } + DBUG_RETURN(1); +} + +int init_intvar_from_file(int* var, IO_CACHE* f, int default_val) +{ + char buf[32]; + DBUG_ENTER("init_intvar_from_file"); + + if (my_b_gets(f, buf, sizeof(buf))) + { + *var = atoi(buf); + DBUG_RETURN(0); + } + else if (default_val) + { + *var = default_val; + DBUG_RETURN(0); + } + DBUG_RETURN(1); +} |