mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 09:36:15 +02:00
Fix macOS build, where le32toh is not available
This commit is contained in:
parent
a115c4f4b2
commit
91aea1572e
3 changed files with 15 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
#include "input-accessor.hh"
|
#include "input-accessor.hh"
|
||||||
|
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
#include <endian.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ struct ZipInputAccessor : InputAccessor
|
||||||
zip_uint16_t id, len;
|
zip_uint16_t id, len;
|
||||||
auto extra = zip_file_extra_field_get(zipFile, i, 0, &id, &len, ZIP_FL_CENTRAL);
|
auto extra = zip_file_extra_field_get(zipFile, i, 0, &id, &len, ZIP_FL_CENTRAL);
|
||||||
if (id == 0x5455 && len >= 5)
|
if (id == 0x5455 && len >= 5)
|
||||||
lastModified = std::max(lastModified, (time_t) le32toh(*((uint32_t *) (extra + 1))));
|
lastModified = std::max(lastModified, readLittleEndian<time_t>((unsigned char *) extra + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto slash = strchr(sb.name, '/');
|
auto slash = strchr(sb.name, '/');
|
||||||
|
|
|
@ -331,15 +331,7 @@ T readNum(Source & source)
|
||||||
unsigned char buf[8];
|
unsigned char buf[8];
|
||||||
source((char *) buf, sizeof(buf));
|
source((char *) buf, sizeof(buf));
|
||||||
|
|
||||||
uint64_t n =
|
auto n = readLittleEndian<uint64_t>(buf);
|
||||||
((uint64_t) buf[0]) |
|
|
||||||
((uint64_t) buf[1] << 8) |
|
|
||||||
((uint64_t) buf[2] << 16) |
|
|
||||||
((uint64_t) buf[3] << 24) |
|
|
||||||
((uint64_t) buf[4] << 32) |
|
|
||||||
((uint64_t) buf[5] << 40) |
|
|
||||||
((uint64_t) buf[6] << 48) |
|
|
||||||
((uint64_t) buf[7] << 56);
|
|
||||||
|
|
||||||
if (n > (uint64_t) std::numeric_limits<T>::max())
|
if (n > (uint64_t) std::numeric_limits<T>::max())
|
||||||
throw SerialisationError("serialised integer %d is too large for type '%s'", n, typeid(T).name());
|
throw SerialisationError("serialised integer %d is too large for type '%s'", n, typeid(T).name());
|
||||||
|
|
|
@ -506,6 +506,17 @@ std::optional<N> string2Float(const std::string_view s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a little-endian integer to host order. */
|
||||||
|
template<typename T>
|
||||||
|
T readLittleEndian(unsigned char * p)
|
||||||
|
{
|
||||||
|
T x = 0;
|
||||||
|
for (size_t i = 0; i < sizeof(x); ++i)
|
||||||
|
x |= *p++ << (i * 8);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return true iff `s' starts with `prefix'. */
|
/* Return true iff `s' starts with `prefix'. */
|
||||||
bool hasPrefix(std::string_view s, std::string_view prefix);
|
bool hasPrefix(std::string_view s, std::string_view prefix);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue