2 * nmrpflash - Netgear Unbrick Utility
3 * Copyright (C) 2016 Joseph Lehner <joseph.c.lehner@gmail.com>
5 * nmrpflash is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * nmrpflash is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with nmrpflash. If not, see <http://www.gnu.org/licenses/>.
27 #include <mach/mach_time.h>
30 volatile sig_atomic_t g_interrupted = 0;
32 time_t time_monotonic()
34 #ifndef NMRPFLASH_WINDOWS
37 clock_gettime(CLOCK_MONOTONIC, &ts);
40 static double factor = 0.0;
41 mach_timebase_info_data_t timebase;
43 mach_timebase_info(&timebase);
44 factor = (double)timebase.numer / timebase.denom;
47 return round(mach_absolute_time() * factor / 1e9);
50 return round(GetTickCount() / 1000.0);
54 char *lltostr(long long ll, int base)
57 snprintf(buf, sizeof(buf) - 1, (base == 16 ? "%llx" : (base == 8 ? "%llo" : "%lld")), ll);
61 uint32_t bitcount(uint32_t n)
70 uint32_t netmask(uint32_t count)
72 return htonl(count <= 32 ? 0xffffffff << (32 - count) : 0);
75 void xperror(const char *msg)