Changeset 14193
- Timestamp:
- Sep 8, 2013, 6:27:27 PM (9 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/log.c
r13966 r14193 159 159 int milliseconds; 160 160 161 gettimeofday (&tv, NULL);161 tr_gettimeofday (&tv); 162 162 163 163 seconds = tv.tv_sec; -
trunk/libtransmission/session.c
r14190 r14193 670 670 671 671 /* schedule the next timer for right after the next second begins */ 672 gettimeofday (&tv, NULL);672 tr_gettimeofday (&tv); 673 673 usec = 1000000 - tv.tv_usec; 674 674 if (usec > max) -
trunk/libtransmission/utils.c
r14116 r14193 50 50 #define WINVER WindowsXP /* freeaddrinfo (), getaddrinfo (), getnameinfo () */ 51 51 #include <direct.h> /* _getcwd () */ 52 #include <windows.h> /* Sleep () */52 #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime () */ 53 53 #endif 54 54 … … 84 84 } 85 85 86 int 87 tr_gettimeofday (struct timeval * tv) 88 { 89 #ifdef _MSC_VER 90 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 91 92 FILETIME ft; 93 uint64_t tmp = 0; 94 95 if (tv == NULL) 96 { 97 errno = EINVAL; 98 return -1; 99 } 100 101 GetSystemTimeAsFileTime(&ft); 102 tmp |= ft.dwHighDateTime; 103 tmp <<= 32; 104 tmp |= ft.dwLowDateTime; 105 tmp /= 10; /* to microseconds */ 106 tmp -= DELTA_EPOCH_IN_MICROSECS; 107 108 tv->tv_sec = tmp / 1000000UL; 109 tv->tv_usec = tmp % 1000000UL; 110 111 return 0; 112 113 #undef DELTA_EPOCH_IN_MICROSECS 114 #else 115 116 return gettimeofday (tv, NULL); 117 118 #endif 119 } 120 86 121 /*** 87 122 **** … … 249 284 tr_basename (const char * path) 250 285 { 286 #ifdef _MSC_VER 287 288 char fname[_MAX_FNAME], ext[_MAX_EXT]; 289 if (_splitpath_s (path, NULL, 0, NULL, 0, fname, sizeof (fname), ext, sizeof (ext)) == 0) 290 { 291 const size_t tmpLen = strlen(fname) + strlen(ext) + 2; 292 char * const tmp = tr_malloc (tmpLen); 293 if (tmp != NULL) 294 { 295 if (_makepath_s (tmp, tmpLen, NULL, NULL, fname, ext) == 0) 296 return tmp; 297 298 tr_free (tmp); 299 } 300 } 301 302 return tr_strdup ("."); 303 304 #else 305 251 306 char * tmp = tr_strdup (path); 252 307 char * ret = tr_strdup (basename (tmp)); 253 308 tr_free (tmp); 254 309 return ret; 310 311 #endif 255 312 } 256 313 … … 258 315 tr_dirname (const char * path) 259 316 { 317 #ifdef _MSC_VER 318 319 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 320 if (_splitpath_s (path, drive, sizeof (drive), dir, sizeof (dir), NULL, 0, NULL, 0) == 0) 321 { 322 const size_t tmpLen = strlen(drive) + strlen(dir) + 2; 323 char * const tmp = tr_malloc (tmpLen); 324 if (tmp != NULL) 325 { 326 if (_makepath_s (tmp, tmpLen, drive, dir, NULL, NULL) == 0) 327 { 328 size_t len = strlen(tmp); 329 while (len > 0 && (tmp[len - 1] == '/' || tmp[len - 1] == '\\')) 330 tmp[--len] = '\0'; 331 332 return tmp; 333 } 334 335 tr_free (tmp); 336 } 337 } 338 339 return tr_strdup ("."); 340 341 #else 342 260 343 char * tmp = tr_strdup (path); 261 344 char * ret = tr_strdup (dirname (tmp)); 262 345 tr_free (tmp); 263 346 return ret; 347 348 #endif 264 349 } 265 350 … … 648 733 struct timeval tv; 649 734 650 gettimeofday (&tv, NULL);735 tr_gettimeofday (&tv); 651 736 return (uint64_t) tv.tv_sec * 1000 + (tv.tv_usec / 1000); 652 737 } -
trunk/libtransmission/utils.h
r13991 r14193 17 17 #include <stddef.h> /* size_t */ 18 18 #include <time.h> /* time_t */ 19 19 20 20 21 #ifdef __cplusplus … … 388 389 /** @brief Portability wrapper for localtime_r () that uses the system implementation if available */ 389 390 struct tm * tr_localtime_r (const time_t *_clock, struct tm *_result); 391 392 struct timeval; 393 394 /** @brief Portability wrapper for gettimeofday (), with tz argument dropped */ 395 int tr_gettimeofday (struct timeval * tv); 390 396 391 397
Note: See TracChangeset
for help on using the changeset viewer.