|
version 1.1.1.3, 2016/11/01 09:54:32
|
version 1.1.1.4, 2021/03/17 00:32:36
|
|
Line 3
|
Line 3
|
| * |
* |
| * Copyright (C) 1998 Andrew Tridgell |
* Copyright (C) 1998 Andrew Tridgell |
| * Copyright (C) 2002 Martin Pool |
* Copyright (C) 2002 Martin Pool |
| * Copyright (C) 2004-2015 Wayne Davison | * Copyright (C) 2004-2020 Wayne Davison |
| * |
* |
| * This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
|
Line 24
|
Line 24
|
| |
|
| static char number_separator; |
static char number_separator; |
| |
|
| #ifndef HAVE_STRDUP | char get_number_separator(void) |
| char *strdup(char *s) | |
| { |
{ |
| int len = strlen(s) + 1; | if (!number_separator) { |
| char *ret = (char *)malloc(len); | char buf[32]; |
| if (ret) | snprintf(buf, sizeof buf, "%f", 3.14); |
| memcpy(ret, s, len); | if (strchr(buf, '.') != NULL) |
| return ret; | number_separator = ','; |
| | else |
| | number_separator = '.'; |
| | } |
| | |
| | return number_separator; |
| } |
} |
| #endif |
|
| |
|
| |
char get_decimal_point(void) |
| |
{ |
| |
return get_number_separator() == ',' ? '.' : ','; |
| |
} |
| |
|
| #ifndef HAVE_GETCWD |
#ifndef HAVE_GETCWD |
| char *getcwd(char *buf, int size) |
char *getcwd(char *buf, int size) |
| { |
{ |
|
Line 79 static char number_separator;
|
Line 87 static char number_separator;
|
| |
|
| #ifndef HAVE_STRPBRK |
#ifndef HAVE_STRPBRK |
| /** |
/** |
| * Find the first ocurrence in @p s of any character in @p accept. | * Find the first occurrence in @p s of any character in @p accept. |
| * |
* |
| * Derived from glibc |
* Derived from glibc |
| **/ |
**/ |
|
Line 155 int sys_gettimeofday(struct timeval *tv)
|
Line 163 int sys_gettimeofday(struct timeval *tv)
|
| #endif |
#endif |
| } |
} |
| |
|
| #define HUMANIFY(mult) \ |
|
| do { \ |
|
| if (num >= mult || num <= -mult) { \ |
|
| double dnum = (double)num / mult; \ |
|
| char units; \ |
|
| if (num < 0) \ |
|
| dnum = -dnum; \ |
|
| if (dnum < mult) \ |
|
| units = 'K'; \ |
|
| else if ((dnum /= mult) < mult) \ |
|
| units = 'M'; \ |
|
| else if ((dnum /= mult) < mult) \ |
|
| units = 'G'; \ |
|
| else { \ |
|
| dnum /= mult; \ |
|
| units = 'T'; \ |
|
| } \ |
|
| if (num < 0) \ |
|
| dnum = -dnum; \ |
|
| snprintf(bufs[n], sizeof bufs[0], "%.2f%c", dnum, units); \ |
|
| return bufs[n]; \ |
|
| } \ |
|
| } while (0) |
|
| |
|
| /* Return the int64 number as a string. If the human_flag arg is non-zero, |
/* Return the int64 number as a string. If the human_flag arg is non-zero, |
| * we may output the number in K, M, G, or T units. If we don't add a unit |
* we may output the number in K, M, G, or T units. If we don't add a unit |
| * suffix, we will append the fract string, if it is non-NULL. We can |
* suffix, we will append the fract string, if it is non-NULL. We can |
|
Line 190 char *do_big_num(int64 num, int human_flag, const char
|
Line 174 char *do_big_num(int64 num, int human_flag, const char
|
| char *s; |
char *s; |
| int len, negated; |
int len, negated; |
| |
|
| if (human_flag && !number_separator) { | if (human_flag && !number_separator) |
| char buf[32]; | (void)get_number_separator(); |
| snprintf(buf, sizeof buf, "%f", 3.14); | |
| if (strchr(buf, '.') != NULL) | |
| number_separator = ','; | |
| else | |
| number_separator = '.'; | |
| } | |
| |
|
| n = (n + 1) % (sizeof bufs / sizeof bufs[0]); |
n = (n + 1) % (sizeof bufs / sizeof bufs[0]); |
| |
|
| if (human_flag > 1) { |
if (human_flag > 1) { |
| if (human_flag == 2) | int mult = human_flag == 2 ? 1000 : 1024; |
| HUMANIFY(1000); | if (num >= mult || num <= -mult) { |
| else | double dnum = (double)num / mult; |
| HUMANIFY(1024); | char units; |
| | if (num < 0) |
| | dnum = -dnum; |
| | if (dnum < mult) |
| | units = 'K'; |
| | else if ((dnum /= mult) < mult) |
| | units = 'M'; |
| | else if ((dnum /= mult) < mult) |
| | units = 'G'; |
| | else if ((dnum /= mult) < mult) |
| | units = 'T'; |
| | else { |
| | dnum /= mult; |
| | units = 'P'; |
| | } |
| | if (num < 0) |
| | dnum = -dnum; |
| | snprintf(bufs[n], sizeof bufs[0], "%.2f%c", dnum, units); |
| | return bufs[n]; |
| | } |
| } |
} |
| |
|
| s = bufs[n] + sizeof bufs[0] - 1; |
s = bufs[n] + sizeof bufs[0] - 1; |