~ubuntu-branches/ubuntu/wily/mysql-5.6/wily

« back to all changes in this revision

Viewing changes to mysys_ssl/my_getopt.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-04-16 20:07:10 UTC
  • mto: (1.3.9 vivid-proposed)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20150416200710-pcrsa022082zj46k
Tags: upstream-5.6.24
ImportĀ upstreamĀ versionĀ 5.6.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
 
1
/* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
1012
1012
  return num;
1013
1013
}
1014
1014
 
 
1015
/*
 
1016
  function: eval_num_suffix_ull
 
1017
 
 
1018
  Transforms a number with a suffix to unsigned longlong number. Suffix can
 
1019
  be k|K for kilo, m|M for mega or g|G for giga.
 
1020
*/
 
1021
 
 
1022
static ulonglong eval_num_suffix_ull(char *argument, int *error,
 
1023
                                     char *option_name)
 
1024
{
 
1025
  char *endchar;
 
1026
  ulonglong num;
 
1027
 
 
1028
  *error= 0;
 
1029
  errno= 0;
 
1030
  num= strtoull(argument, &endchar, 10);
 
1031
  if (errno == ERANGE)
 
1032
  {
 
1033
    my_getopt_error_reporter(ERROR_LEVEL,
 
1034
                             "Incorrect unsigned integer value:'%s'", argument);
 
1035
    *error= 1;
 
1036
    return 0;
 
1037
  }
 
1038
  if (*endchar == 'k' || *endchar == 'K')
 
1039
    num*= 1024L;
 
1040
  else if (*endchar == 'm' || *endchar == 'M')
 
1041
    num*= 1024L * 1024L;
 
1042
  else if (*endchar == 'g' || *endchar == 'G')
 
1043
    num*= 1024L * 1024L * 1024L;
 
1044
  else if (*endchar)
 
1045
  {
 
1046
    fprintf(stderr,
 
1047
            "Unknown suffix '%c' used for variable '%s' (value '%s')\n",
 
1048
            *endchar, option_name, argument);
 
1049
    *error= 1;
 
1050
    return 0;
 
1051
  }
 
1052
  return num;
 
1053
}
 
1054
 
1015
1055
/* 
1016
1056
  function: getopt_ll
1017
1057
 
1116
1156
 
1117
1157
static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err)
1118
1158
{
1119
 
  ulonglong num= eval_num_suffix(arg, err, (char*) optp->name);
 
1159
  ulonglong num= eval_num_suffix_ull(arg, err, (char*) optp->name);
1120
1160
  return getopt_ull_limit_value(num, optp, NULL);
1121
1161
}
1122
1162