/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 * SPDX-License-Identifier: curl
 *
 ***************************************************************************/
#include "tool_setup.h"

#include "tool_operate.h"
#include "tool_progress.h"

/* The point of this function would be to return a string of the input data,
   but never longer than 5 columns (+ one zero byte).
   Add suffix k, M, G when suitable...

   Unit test @1622
*/
UNITTEST char *max5data(curl_off_t bytes, char *max5, size_t mlen)
{
  /* a signed 64-bit value is 8192 petabytes maximum */
  const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 };
  int k = 0;
  if(bytes < 100000) {
    curl_msnprintf(max5, mlen, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
    return max5;
  }

  do {
    curl_off_t nbytes = bytes / 1024;
    if(nbytes < 100) {
      /* display with a decimal */
      curl_msnprintf(max5, mlen, "%2" CURL_FORMAT_CURL_OFF_T ".%"
                     CURL_FORMAT_CURL_OFF_T "%c", bytes / 1024,
