Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 946da7c5 authored by cfig's avatar cfig
Browse files

libsparse: replace legacy min() with std::min()

this makes libsparse compile with MacOS clang++
Test: "libsparse" compiles and works fine under both Linux and MacOS

Change-Id: Ifcf018b856d2fe5f1dac7eeddd72de2810be66c5
parent 19b68a66
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1

#include <algorithm>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
@@ -48,13 +49,6 @@
#define off64_t off_t
#endif

#define min(a, b)        \
  ({                     \
    typeof(a) _a = (a);  \
    typeof(b) _b = (b);  \
    (_a < _b) ? _a : _b; \
  })

#define SPARSE_HEADER_MAJOR_VER 1
#define SPARSE_HEADER_MINOR_VER 0
#define SPARSE_HEADER_LEN (sizeof(sparse_header_t))
@@ -231,7 +225,7 @@ static int gz_file_write(struct output_file* out, void* data, size_t len) {
  struct output_file_gz* outgz = to_output_file_gz(out);

  while (len > 0) {
    ret = gzwrite(outgz->gz_fd, data, min(len, (unsigned int)INT_MAX));
    ret = gzwrite(outgz->gz_fd, data, std::min<unsigned int>(len, (unsigned int)INT_MAX));
    if (ret == 0) {
      error("gzwrite %s", gzerror(outgz->gz_fd, nullptr));
      return -1;
@@ -268,7 +262,7 @@ static int callback_file_skip(struct output_file* out, int64_t off) {
  int ret;

  while (off > 0) {
    to_write = min(off, (int64_t)INT_MAX);
    to_write = std::min(off, (int64_t)INT_MAX);
    ret = outc->write(outc->priv, nullptr, to_write);
    if (ret < 0) {
      return ret;
@@ -470,7 +464,7 @@ static int write_normal_fill_chunk(struct output_file* out, unsigned int len, ui
  }

  while (len) {
    write_len = min(len, out->block_size);
    write_len = std::min(len, out->block_size);
    ret = out->ops->write(out, out->fill_buf, write_len);
    if (ret < 0) {
      return ret;