Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
[Portability] strtol and strtoul fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
enricogior committed Jul 1, 2016
1 parent 47975c0 commit f7e6eea
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 41 deletions.
2 changes: 1 addition & 1 deletion deps/hiredis/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static char *nextArgument(char *start, char **str, size_t *len) {
if (p == NULL) return NULL;
}

*len = (int)PORT_STRTOL(p+1,NULL,10);
*len = (int)strtol(p+1,NULL,10);
p = strchr(p,'\r');
assert(p);
*str = p+2;
Expand Down
5 changes: 5 additions & 0 deletions src/Win32_Interop/Win32_APIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#define strcasecmp _stricmp
#define strtoll _strtoi64

#ifdef _WIN64
#define strtol _strtoi64
#define strtoul _strtoui64
#endif

#define sleep(x) Sleep((x)*1000)
/* Redis calls usleep(1) to give thread some time.
* Sleep(0) should do the same on Windows.
Expand Down
6 changes: 0 additions & 6 deletions src/Win32_Interop/win32_types_hiredis.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,4 @@ typedef int pid_t;
typedef unsigned __int32 u_int32_t;
#endif

#ifdef _WIN64
#define PORT_STRTOL strtoll
#else
#define PORT_STRTOL strtol
#endif

#endif
6 changes: 3 additions & 3 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ sds catAppendOnlyExpireAtCommand(sds buf, struct redisCommand *cmd, robj *key, r
PORT_LONGLONG when;
robj *argv[3];

/* Make sure we can use PORT_STRTOL */
/* Make sure we can use strtol */
seconds = getDecodedObject(seconds);
when = PORT_STRTOL(seconds->ptr,NULL,10);
when = strtol(seconds->ptr,NULL,10);
/* Convert argument into milliseconds for EXPIRE, SETEX, EXPIREAT */
if (cmd->proc == expireCommand || cmd->proc == setexCommand ||
cmd->proc == expireatCommand)
Expand Down Expand Up @@ -688,7 +688,7 @@ int loadAppendOnlyFile(char *filename) {
goto readerr;
}
if (buf[0] != '$') goto fmterr;
len = PORT_STRTOL(buf+1,NULL,10);
len = strtol(buf+1,NULL,10);
argsds = sdsnewlen(NULL,len);
if (len && fread(argsds,len,1,fp) == 0) {
sdsfree(argsds);
Expand Down
24 changes: 12 additions & 12 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void loadServerConfigFromString(char *config) {
server.unixsocket = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"unixsocketperm") && argc == 2) {
errno = 0;
server.unixsocketperm = (mode_t)PORT_STRTOL(argv[1], NULL, 8);
server.unixsocketperm = (mode_t)strtol(argv[1], NULL, 8);
if (errno || server.unixsocketperm > 0777) {
err = "Invalid socket file permissions"; goto loaderr;
}
Expand Down Expand Up @@ -549,7 +549,7 @@ void loadServerConfigFromString(char *config) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"cluster-node-timeout") && argc == 2) {
server.cluster_node_timeout = PORT_STRTOL(argv[1],NULL,10);
server.cluster_node_timeout = strtol(argv[1],NULL,10);
if (server.cluster_node_timeout <= 0) {
err = "cluster node timeout must be 1 or greater"; goto loaderr;
}
Expand All @@ -570,21 +570,21 @@ void loadServerConfigFromString(char *config) {
goto loaderr;
}
} else if (!strcasecmp(argv[0],"lua-time-limit") && argc == 2) {
server.lua_time_limit = PORT_STRTOL(argv[1],NULL,10);
server.lua_time_limit = strtol(argv[1],NULL,10);
} else if (!strcasecmp(argv[0],"slowlog-log-slower-than") &&
argc == 2)
{
server.slowlog_log_slower_than = PORT_STRTOL(argv[1],NULL,10);
server.slowlog_log_slower_than = strtol(argv[1],NULL,10);
} else if (!strcasecmp(argv[0],"latency-monitor-threshold") &&
argc == 2)
{
server.latency_monitor_threshold = PORT_STRTOL(argv[1],NULL,10);
server.latency_monitor_threshold = strtol(argv[1],NULL,10);
if (server.latency_monitor_threshold < 0) {
err = "The latency threshold can't be negative";
goto loaderr;
}
} else if (!strcasecmp(argv[0],"slowlog-max-len") && argc == 2) {
server.slowlog_max_len = (PORT_ULONG)(PORT_STRTOL(argv[1],NULL,10)); WIN_PORT_FIX /* cast (PORT_ULONG) */
server.slowlog_max_len = (PORT_ULONG)(strtol(argv[1],NULL,10)); WIN_PORT_FIX /* cast (PORT_ULONG) */
} else if (!strcasecmp(argv[0],"client-output-buffer-limit") &&
argc == 5)
{
Expand Down Expand Up @@ -871,7 +871,7 @@ void configSetCommand(client *c) {
char *eptr;
PORT_LONG val;

val = PORT_STRTOL(v[j], &eptr, 10);
val = strtol(v[j], &eptr, 10);
if (eptr[0] != '\0' ||
((j & 1) == 0 && val < 1) ||
((j & 1) == 1 && val < 0)) {
Expand All @@ -885,8 +885,8 @@ void configSetCommand(client *c) {
time_t seconds;
int changes;

seconds = PORT_STRTOL(v[j],NULL,10);
changes = PORT_STRTOL(v[j+1],NULL,10);
seconds = strtol(v[j],NULL,10);
changes = strtol(v[j+1],NULL,10);
appendServerSaveParams(seconds, changes);
}
sdsfreesplitres(v,vlen);
Expand Down Expand Up @@ -931,9 +931,9 @@ void configSetCommand(client *c) {
int soft_seconds;

class = getClientTypeByName(v[j]);
hard = PORT_STRTOL(v[j+1],NULL,10);
soft = PORT_STRTOL(v[j+2],NULL,10);
soft_seconds = PORT_STRTOL(v[j+3],NULL,10);
hard = strtol(v[j+1],NULL,10);
soft = strtol(v[j+2],NULL,10);
soft_seconds = strtol(v[j+3],NULL,10);

server.client_obuf_limits[class].hard_limit_bytes = hard;
server.client_obuf_limits[class].soft_limit_bytes = soft;
Expand Down
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ int getLongLongFromObject(robj *o, PORT_LONGLONG *target) {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
if (sdsEncodedObject(o)) {
errno = 0;
value = PORT_STRTOL(o->ptr, &eptr, 10);
value = strtol(o->ptr, &eptr, 10);
if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
errno == ERANGE)
return C_ERR;
Expand Down
2 changes: 1 addition & 1 deletion src/rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int rdbTryIntegerEncoding(char *s, size_t len, unsigned char *enc) {
char *endptr, buf[32];

/* Check if it's possible to encode this value as a number */
value = PORT_STRTOL(s, &endptr, 10);
value = strtol(s, &endptr, 10);
if (endptr[0] != '\0') return 0;
ll2string(buf,32,value);

Expand Down
2 changes: 1 addition & 1 deletion src/redis-check-aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int readLong(FILE *fp, char prefix, PORT_LONG *target) {
ERROR("Expected prefix '%c', got: '%c'",buf[0],prefix);
return 0;
}
*target = PORT_STRTOL(buf+1,&eptr,10);
*target = strtol(buf+1,&eptr,10);
return consumeNewline(eptr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/redis-check-rdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int processHeader(void) {
ERROR("Wrong signature in header");
}

dump_version = (int)PORT_STRTOL(buf + 5, NULL, 10);
dump_version = (int)strtol(buf + 5, NULL, 10);
if (dump_version < 1 || dump_version > 6) {
ERROR("Unknown RDB format version: %d", dump_version);
}
Expand Down
10 changes: 5 additions & 5 deletions src/redis-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ static sds cliVersion(void) {
version = sdscatprintf(sdsempty(), "%s", REDIS_VERSION);

/* Add git commit and working tree status when available */
if (PORT_STRTOL(redisGitSHA1(),NULL,16)) {
if (strtol(redisGitSHA1(),NULL,16)) {
version = sdscatprintf(version, " (git:%s", redisGitSHA1());
if (PORT_STRTOL(redisGitDirty(),NULL,10))
if (strtol(redisGitDirty(),NULL,10))
version = sdscatprintf(version, "-dirty");
version = sdscat(version, ")");
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ static int parseOptions(int argc, char **argv) {
} else if (!strcmp(argv[i],"-s") && !lastarg) {
config.hostsocket = argv[++i];
} else if (!strcmp(argv[i],"-r") && !lastarg) {
config.repeat = (PORT_LONG) PORT_STRTOL(argv[++i],NULL,10);
config.repeat = (PORT_LONG) strtol(argv[++i],NULL,10);
} else if (!strcmp(argv[i],"-i") && !lastarg) {
double seconds = atof(argv[++i]);
config.interval = (PORT_LONG) (seconds*1000000);
Expand All @@ -1047,7 +1047,7 @@ static int parseOptions(int argc, char **argv) {
config.latency_history = 1;
} else if (!strcmp(argv[i],"--lru-test") && !lastarg) {
config.lru_test_mode = 1;
config.lru_test_sample_size = PORT_STRTOL(argv[++i],NULL,10);
config.lru_test_sample_size = strtol(argv[++i],NULL,10);
} else if (!strcmp(argv[i],"--slave")) {
config.slave_mode = 1;
} else if (!strcmp(argv[i],"--stat")) {
Expand Down Expand Up @@ -2265,7 +2265,7 @@ static PORT_LONG getLongInfoField(char *info, char *field) {
PORT_LONG l;

if (!value) return PORT_LONG_MIN;
l = PORT_STRTOL(value,NULL,10);
l = strtol(value,NULL,10);
zfree(value);
return l;
}
Expand Down
4 changes: 2 additions & 2 deletions src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
"MASTER <-> SLAVE sync: receiving streamed RDB from master");
} else {
usemark = 0;
server.repl_transfer_size = PORT_STRTOL(buf+1,NULL,10);
server.repl_transfer_size = strtol(buf+1,NULL,10);
serverLog(LL_NOTICE,
"MASTER <-> SLAVE sync: receiving %lld bytes from master",
(PORT_LONGLONG) server.repl_transfer_size);
Expand Down Expand Up @@ -1443,7 +1443,7 @@ int slaveTryPartialResynchronization(int fd, int read_reply) {
} else {
memcpy(server.repl_master_runid, runid, offset-runid-1);
server.repl_master_runid[CONFIG_RUN_ID_SIZE] = '\0';
server.repl_master_initial_offset = PORT_STRTOL(offset,NULL,10);
server.repl_master_initial_offset = strtol(offset,NULL,10);
serverLog(LL_NOTICE,"Full resync from master: %s:%lld",
server.repl_master_runid,
server.repl_master_initial_offset);
Expand Down
2 changes: 1 addition & 1 deletion src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
if (sdslen(l) >= 32 &&
!memcmp(l,"master_link_down_since_seconds",30))
{
ri->master_link_down_time = PORT_STRTOL(l+31,NULL,10)*1000;
ri->master_link_down_time = strtol(l+31,NULL,10)*1000;
}

/* role:<role> */
Expand Down
6 changes: 3 additions & 3 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2927,7 +2927,7 @@ sds genRedisInfoString(char *section) {
"config_file:%s\r\n",
REDIS_VERSION,
redisGitSHA1(),
PORT_STRTOL(redisGitDirty(),NULL,10) > 0,
strtol(redisGitDirty(),NULL,10) > 0,
(PORT_ULONGLONG) redisBuildId(),
mode,
#ifdef _WIN32
Expand Down Expand Up @@ -3755,7 +3755,7 @@ void redisAsciiArt(void) {
"Redis %s (%s/%d) %s bit, %s mode, port %d, pid %ld ready to start.",
REDIS_VERSION,
redisGitSHA1(),
PORT_STRTOL(redisGitDirty(),NULL,10) > 0,
strtol(redisGitDirty(),NULL,10) > 0,
(sizeof(PORT_LONG) == 8) ? "64" : "32",
mode, server.port,
(PORT_LONG) getpid()
Expand All @@ -3764,7 +3764,7 @@ void redisAsciiArt(void) {
snprintf(buf,1024*16,ascii_logo,
REDIS_VERSION,
redisGitSHA1(),
PORT_STRTOL(redisGitDirty(),NULL,10) > 0,
strtol(redisGitDirty(),NULL,10) > 0,
(sizeof(PORT_LONG) == 8) ? "64" : "32",
mode, server.port,
(PORT_LONG) getpid()
Expand Down
4 changes: 2 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ PORT_LONGLONG memtoll(const char *p, int *err) {
return 0;
}

/* Copy the digits into a buffer, we'll use PORT_STRTOL() to convert
/* Copy the digits into a buffer, we'll use strtol() to convert
* the digit (without the unit) into a number. */
digits = (unsigned int)(u-p); WIN_PORT_FIX /* cast (unsigned int) */
if (digits >= sizeof(buf)) {
Expand All @@ -230,7 +230,7 @@ PORT_LONGLONG memtoll(const char *p, int *err) {

char *endptr;
errno = 0;
val = PORT_STRTOL(buf,&endptr,10);
val = strtol(buf,&endptr,10);
if ((val == 0 && errno == EINVAL) || *endptr != '\0') {
if (err) *err = 1;
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/zmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ size_t zmalloc_get_rss(void) {
if (!x) return 0;
*x = '\0';

rss = PORT_STRTOL(p,NULL,10);
rss = strtol(p,NULL,10);
rss *= page;
return rss;
}
Expand Down Expand Up @@ -378,7 +378,7 @@ size_t zmalloc_get_smap_bytes_by_field(char *field) {
char *p = strchr(line,'k');
if (p) {
*p = '\0';
bytes += PORT_STRTOL(line+flen,NULL,10) * 1024;
bytes += strtol(line+flen,NULL,10) * 1024;
}
}
}
Expand Down

0 comments on commit f7e6eea

Please sign in to comment.