diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-09 19:13:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-09 19:13:08 +0000 |
commit | 7daab4034dff228245cd8cdc16191457087fcd01 (patch) | |
tree | 40db4f6d36b0d8d89857d3066793ff63067270e4 /src | |
parent | cd753df7bf741f5063d672afaf23390ebbd55c48 (diff) | |
download | tor-7daab4034dff228245cd8cdc16191457087fcd01.tar.gz tor-7daab4034dff228245cd8cdc16191457087fcd01.zip |
Fix windows build for VC6; centralize newline-fiasco-damage-control logic
svn:r2756
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 29 | ||||
-rw-r--r-- | src/or/router.c | 1 | ||||
-rw-r--r-- | src/or/routerlist.c | 1 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c index d3c044db88..8f0922c399 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -384,6 +384,7 @@ tor_parse_ulong(const char *s, int base, unsigned long min, CHECK_STRTOX_RESULT(); } +/** Only base 10 is guaranteed to work for now. */ uint64_t tor_parse_uint64(const char *s, int base, uint64_t min, uint64_t max, int *ok, char **next) @@ -394,7 +395,15 @@ tor_parse_uint64(const char *s, int base, uint64_t min, #ifdef HAVE_STRTOULL r = (uint64_t)strtoull(s, &endptr, base); #elif defined(MS_WINDOWS) +#if _MSC_VER < 1300 + tor_assert(base <= 10); + r = (uint64_t)_atoi64(s); + endptr = (char*)s; + while(isspace(*endptr)) endptr++; + while(isdigit(*endptr)) endptr++; +#else r = (uint64_t)_strtoui64(s, &endptr, base); +#endif #elif SIZEOF_LONG == 8 r = (uint64_t)strtoul(s, &endptr, base); #else @@ -779,6 +788,11 @@ int check_private_dir(const char *dirname, cpd_check_t check) int write_str_to_file(const char *fname, const char *str, int bin) { +#ifdef MS_WINDOWS + if (strchr(str, '\r')) { + log_fn(LOG_WARN, "How odd. Writing a string that does contain CR already."); + } +#endif return write_bytes_to_file(fname, str, strlen(str), bin); } @@ -849,7 +863,10 @@ char *read_file_to_str(const char *filename, int bin) { tor_free(string); close(fd); return NULL; - } else if (bin && r != statbuf.st_size) { + } + string[r] = '\0'; /* NUL-terminate the result. */ + + if (bin && r != statbuf.st_size) { /* If we're in binary mode, then we'd better have an exact match for * size. Otherwise, win32 encoding may throw us off, and that's okay. */ log_fn(LOG_WARN,"Could read only %d of %ld bytes of file '%s'.", @@ -858,9 +875,17 @@ char *read_file_to_str(const char *filename, int bin) { close(fd); return NULL; } +#ifdef MS_WINDOWS + if (!bin && strchr(string, '\r')) { + if (strchr(string, '\r')) { + log_fn(LOG_DEBUG, "We didn't convert CRLF to LF as well as we hoped when reading %s. Coping.", + filename); + tor_strstrip(string, "\r"); + } + } +#endif close(fd); - string[statbuf.st_size] = 0; /* null terminate it */ return string; } diff --git a/src/or/router.c b/src/or/router.c index bae0a57d9e..0d8ff88721 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -354,7 +354,6 @@ int init_keys(void) { if(!cp) { log_fn(LOG_INFO,"Cached directory %s not present. Ok.",keydir); } else { - tor_strstrip(cp,"\r"); /* XXXX Workaround for win32 read_file_to_str bug. */ if(dirserv_load_from_directory_string(cp) < 0){ log_fn(LOG_ERR, "Cached directory %s is corrupt", keydir); tor_free(cp); diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7506da267e..5ae522ac32 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -60,7 +60,6 @@ int router_reload_router_list(void) } s = read_file_to_str(filename,0); if (s) { - tor_strstrip(s,"\r"); /* XXXX This is a bug workaround for win32. */ log_fn(LOG_INFO, "Loading cached directory from %s", filename); is_recent = st.st_mtime > time(NULL) - 60*15; if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) { |