Added guac_parse_int, which handles 64-bit integers regardless of native arch.
This commit is contained in:
parent
8242c37f11
commit
532ad2137b
@ -114,6 +114,17 @@ typedef struct GUACIO {
|
||||
*/
|
||||
GUACIO* guac_open(int fd);
|
||||
|
||||
/**
|
||||
* Parses the given string as a decimal number, returning the result as
|
||||
* a 64-bit signed value. This value will be 64-bit regardless of platform.
|
||||
*
|
||||
* @param str The string to parse into a 64-bit integer.
|
||||
* @return The 64-bit integer representation of the number in the given
|
||||
* string, undefined if the string does not contain a properly
|
||||
* formatted number.
|
||||
*/
|
||||
int64_t guac_parse_int(const char* str);
|
||||
|
||||
/**
|
||||
* Writes the given unsigned int to the given GUACIO object. The data
|
||||
* written may be buffered until the buffer is flushed automatically or
|
||||
|
@ -53,9 +53,9 @@ __guac_instruction_handler_mapping __guac_instruction_handler_map[] = {
|
||||
};
|
||||
|
||||
/* Guacamole instruction handlers */
|
||||
|
||||
#include <stdio.h>
|
||||
int __guac_handle_sync(guac_client* client, guac_instruction* instruction) {
|
||||
guac_timestamp_t timestamp = atol(instruction->argv[0]);
|
||||
guac_timestamp_t timestamp = guac_parse_int(instruction->argv[0]);
|
||||
|
||||
/* Error if timestamp is in future */
|
||||
if (timestamp > client->last_sent_timestamp)
|
||||
|
@ -98,6 +98,24 @@ ssize_t __guac_write(GUACIO* io, const char* buf, int count) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
int64_t guac_parse_int(const char* str) {
|
||||
|
||||
int sign = 1;
|
||||
int64_t num = 0;
|
||||
|
||||
for (; *str != '\0'; str++) {
|
||||
|
||||
if (*str == '-')
|
||||
sign = -sign;
|
||||
else
|
||||
num = num * 10 + (*str - '0');
|
||||
|
||||
}
|
||||
|
||||
return num * sign;
|
||||
|
||||
}
|
||||
|
||||
ssize_t guac_write_int(GUACIO* io, int64_t i) {
|
||||
|
||||
char buffer[128];
|
||||
|
Loading…
Reference in New Issue
Block a user