longlong
This commit is contained in:
parent
78f566bd6d
commit
185802fbe2
@ -2,6 +2,7 @@
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
@ -197,9 +198,9 @@ scrcpy_print_usage(const char *arg0) {
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
||||
long max, const char *name) {
|
||||
long value;
|
||||
parse_integer_arg(const char *s, long long *out, bool accept_suffix,
|
||||
long long min, long long max, const char *name) {
|
||||
long long value;
|
||||
bool ok;
|
||||
if (accept_suffix) {
|
||||
ok = parse_integer_with_suffix(s, &value);
|
||||
@ -212,8 +213,8 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
||||
}
|
||||
|
||||
if (value < min || value > max) {
|
||||
LOGE("Could not parse %s: value (%ld) out-of-range (%ld; %ld)",
|
||||
name, value, min, max);
|
||||
LOGE("Could not parse %s: value (%" PRIlld ") out-of-range (%"
|
||||
PRIlld "; %" PRIlld ")", name, value, min, max);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -223,8 +224,8 @@ parse_integer_arg(const char *s, long *out, bool accept_suffix, long min,
|
||||
|
||||
static bool
|
||||
parse_bit_rate(const char *s, uint32_t *bit_rate) {
|
||||
long value;
|
||||
bool ok = parse_integer_arg(s, &value, true, 0, 0xFFFFFFFF, "bit-rate");
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, true, 0, 0xFFFFFFFFLL, "bit-rate");
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
@ -235,7 +236,7 @@ parse_bit_rate(const char *s, uint32_t *bit_rate) {
|
||||
|
||||
static bool
|
||||
parse_max_size(const char *s, uint16_t *max_size) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "max size");
|
||||
if (!ok) {
|
||||
return false;
|
||||
@ -247,7 +248,7 @@ parse_max_size(const char *s, uint16_t *max_size) {
|
||||
|
||||
static bool
|
||||
parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 1000, "max fps");
|
||||
if (!ok) {
|
||||
return false;
|
||||
@ -259,7 +260,7 @@ parse_max_fps(const char *s, uint16_t *max_fps) {
|
||||
|
||||
static bool
|
||||
parse_window_position(const char *s, int16_t *position) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, -1, 0x7FFF,
|
||||
"window position");
|
||||
if (!ok) {
|
||||
@ -272,7 +273,7 @@ parse_window_position(const char *s, int16_t *position) {
|
||||
|
||||
static bool
|
||||
parse_window_dimension(const char *s, uint16_t *dimension) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF,
|
||||
"window dimension");
|
||||
if (!ok) {
|
||||
@ -285,7 +286,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) {
|
||||
|
||||
static bool
|
||||
parse_port(const char *s, uint16_t *port) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_arg(s, &value, false, 0, 0xFFFF, "port");
|
||||
if (!ok) {
|
||||
return false;
|
||||
|
@ -36,6 +36,13 @@
|
||||
|
||||
#endif
|
||||
|
||||
// in MinGW, "%ll" is not supported as printf format for long long
|
||||
# ifdef __MINGW32__
|
||||
# define PRIlld "I64d"
|
||||
# else
|
||||
# define PRIlld "lld"
|
||||
# endif
|
||||
|
||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define MIN(X,Y) (X) < (Y) ? (X) : (Y)
|
||||
#define MAX(X,Y) (X) > (Y) ? (X) : (Y)
|
||||
|
@ -63,13 +63,13 @@ strquote(const char *src) {
|
||||
}
|
||||
|
||||
bool
|
||||
parse_integer(const char *s, long *out) {
|
||||
parse_integer(const char *s, long long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
}
|
||||
errno = 0;
|
||||
long value = strtol(s, &endptr, 0);
|
||||
long long value = strtol(s, &endptr, 0);
|
||||
if (errno == ERANGE) {
|
||||
return false;
|
||||
}
|
||||
@ -82,13 +82,13 @@ parse_integer(const char *s, long *out) {
|
||||
}
|
||||
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out) {
|
||||
parse_integer_with_suffix(const char *s, long long *out) {
|
||||
char *endptr;
|
||||
if (*s == '\0') {
|
||||
return false;
|
||||
}
|
||||
errno = 0;
|
||||
long value = strtol(s, &endptr, 0);
|
||||
long long value = strtoll(s, &endptr, 0);
|
||||
if (errno == ERANGE) {
|
||||
return false;
|
||||
}
|
||||
@ -106,8 +106,8 @@ parse_integer_with_suffix(const char *s, long *out) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((value < 0 && LONG_MIN / mul > value) ||
|
||||
(value > 0 && LONG_MAX / mul < value)) {
|
||||
if ((value < 0 && LLONG_MIN / mul > value) ||
|
||||
(value > 0 && LLONG_MAX / mul < value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ strquote(const char *src);
|
||||
// parse s as an integer into value
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer(const char *s, long *out);
|
||||
parse_integer(const char *s, long long *out);
|
||||
|
||||
// parse s as an integer into value
|
||||
// like parse_integer(), but accept 'k'/'K' (x1000) and 'm'/'M' (x1000000) as
|
||||
// suffix
|
||||
// returns true if the conversion succeeded, false otherwise
|
||||
bool
|
||||
parse_integer_with_suffix(const char *s, long *out);
|
||||
parse_integer_with_suffix(const char *s, long long *out);
|
||||
|
||||
// return the index to truncate a UTF-8 string at a valid position
|
||||
size_t
|
||||
|
@ -171,7 +171,7 @@ static void test_utf8_truncate(void) {
|
||||
}
|
||||
|
||||
static void test_parse_integer(void) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
@ -188,7 +188,7 @@ static void test_parse_integer(void) {
|
||||
}
|
||||
|
||||
static void test_parse_integer_with_suffix(void) {
|
||||
long value;
|
||||
long long value;
|
||||
bool ok = parse_integer_with_suffix("1234", &value);
|
||||
assert(ok);
|
||||
assert(value == 1234);
|
||||
|
Loading…
x
Reference in New Issue
Block a user