Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: webrtc/base/win32.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/unixfilesystem.cc ('k') | webrtc/base/win32filesystem.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/win32.h" 11 #include "webrtc/base/win32.h"
12 12
13 #include <winsock2.h> 13 #include <winsock2.h>
14 #include <ws2tcpip.h> 14 #include <ws2tcpip.h>
15 #include <algorithm> 15 #include <algorithm>
16 16
17 #include "webrtc/base/arraysize.h" 17 #include "webrtc/base/arraysize.h"
18 #include "webrtc/base/basictypes.h" 18 #include "webrtc/base/basictypes.h"
19 #include "webrtc/base/byteorder.h" 19 #include "webrtc/base/byteorder.h"
20 #include "webrtc/base/checks.h"
20 #include "webrtc/base/common.h" 21 #include "webrtc/base/common.h"
21 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
22 23
23 namespace rtc { 24 namespace rtc {
24 25
25 // Helper function declarations for inet_ntop/inet_pton. 26 // Helper function declarations for inet_ntop/inet_pton.
26 static const char* inet_ntop_v4(const void* src, char* dst, socklen_t size); 27 static const char* inet_ntop_v4(const void* src, char* dst, socklen_t size);
27 static const char* inet_ntop_v6(const void* src, char* dst, socklen_t size); 28 static const char* inet_ntop_v6(const void* src, char* dst, socklen_t size);
28 static int inet_pton_v4(const char* src, void* dst); 29 static int inet_pton_v4(const char* src, void* dst);
29 static int inet_pton_v6(const char* src, void* dst); 30 static int inet_pton_v6(const char* src, void* dst);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // FILETIME of that time/date, then we add/subtract in appropriate units to 312 // FILETIME of that time/date, then we add/subtract in appropriate units to
312 // convert to/from unix time. 313 // convert to/from unix time.
313 // The units of FILETIME are 100ns intervals, so by multiplying by or dividing 314 // The units of FILETIME are 100ns intervals, so by multiplying by or dividing
314 // by 10000000, we can convert to/from seconds. 315 // by 10000000, we can convert to/from seconds.
315 // 316 //
316 // FileTime = UnixTime*10000000 + FileTime(1970) 317 // FileTime = UnixTime*10000000 + FileTime(1970)
317 // UnixTime = (FileTime-FileTime(1970))/10000000 318 // UnixTime = (FileTime-FileTime(1970))/10000000
318 // 319 //
319 320
320 void FileTimeToUnixTime(const FILETIME& ft, time_t* ut) { 321 void FileTimeToUnixTime(const FILETIME& ft, time_t* ut) {
321 ASSERT(NULL != ut); 322 RTC_DCHECK(NULL != ut);
322 323
323 // FILETIME has an earlier date base than time_t (1/1/1970), so subtract off 324 // FILETIME has an earlier date base than time_t (1/1/1970), so subtract off
324 // the difference. 325 // the difference.
325 SYSTEMTIME base_st; 326 SYSTEMTIME base_st;
326 memset(&base_st, 0, sizeof(base_st)); 327 memset(&base_st, 0, sizeof(base_st));
327 base_st.wDay = 1; 328 base_st.wDay = 1;
328 base_st.wMonth = 1; 329 base_st.wMonth = 1;
329 base_st.wYear = 1970; 330 base_st.wYear = 1970;
330 331
331 FILETIME base_ft; 332 FILETIME base_ft;
332 SystemTimeToFileTime(&base_st, &base_ft); 333 SystemTimeToFileTime(&base_st, &base_ft);
333 334
334 ULARGE_INTEGER base_ul, current_ul; 335 ULARGE_INTEGER base_ul, current_ul;
335 memcpy(&base_ul, &base_ft, sizeof(FILETIME)); 336 memcpy(&base_ul, &base_ft, sizeof(FILETIME));
336 memcpy(&current_ul, &ft, sizeof(FILETIME)); 337 memcpy(&current_ul, &ft, sizeof(FILETIME));
337 338
338 // Divide by big number to convert to seconds, then subtract out the 1970 339 // Divide by big number to convert to seconds, then subtract out the 1970
339 // base date value. 340 // base date value.
340 const ULONGLONG RATIO = 10000000; 341 const ULONGLONG RATIO = 10000000;
341 *ut = static_cast<time_t>((current_ul.QuadPart - base_ul.QuadPart) / RATIO); 342 *ut = static_cast<time_t>((current_ul.QuadPart - base_ul.QuadPart) / RATIO);
342 } 343 }
343 344
344 void UnixTimeToFileTime(const time_t& ut, FILETIME* ft) { 345 void UnixTimeToFileTime(const time_t& ut, FILETIME* ft) {
345 ASSERT(NULL != ft); 346 RTC_DCHECK(NULL != ft);
346 347
347 // FILETIME has an earlier date base than time_t (1/1/1970), so add in 348 // FILETIME has an earlier date base than time_t (1/1/1970), so add in
348 // the difference. 349 // the difference.
349 SYSTEMTIME base_st; 350 SYSTEMTIME base_st;
350 memset(&base_st, 0, sizeof(base_st)); 351 memset(&base_st, 0, sizeof(base_st));
351 base_st.wDay = 1; 352 base_st.wDay = 1;
352 base_st.wMonth = 1; 353 base_st.wMonth = 1;
353 base_st.wYear = 1970; 354 base_st.wYear = 1970;
354 355
355 FILETIME base_ft; 356 FILETIME base_ft;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 wchar_t* start = full_filename + 6; 398 wchar_t* start = full_filename + 6;
398 if (0 == ::GetFullPathName(wfilename, full_len, start, &filepart)) { 399 if (0 == ::GetFullPathName(wfilename, full_len, start, &filepart)) {
399 return false; 400 return false;
400 } 401 }
401 // Add long-path prefix 402 // Add long-path prefix
402 const wchar_t kLongPathPrefix[] = L"\\\\?\\UNC"; 403 const wchar_t kLongPathPrefix[] = L"\\\\?\\UNC";
403 if ((start[0] != L'\\') || (start[1] != L'\\')) { 404 if ((start[0] != L'\\') || (start[1] != L'\\')) {
404 // Non-unc path: <pathname> 405 // Non-unc path: <pathname>
405 // Becomes: \\?\<pathname> 406 // Becomes: \\?\<pathname>
406 start -= 4; 407 start -= 4;
407 ASSERT(start >= full_filename); 408 RTC_DCHECK(start >= full_filename);
408 memcpy(start, kLongPathPrefix, 4 * sizeof(wchar_t)); 409 memcpy(start, kLongPathPrefix, 4 * sizeof(wchar_t));
409 } else if (start[2] != L'?') { 410 } else if (start[2] != L'?') {
410 // Unc path: \\<server>\<pathname> 411 // Unc path: \\<server>\<pathname>
411 // Becomes: \\?\UNC\<server>\<pathname> 412 // Becomes: \\?\UNC\<server>\<pathname>
412 start -= 6; 413 start -= 6;
413 ASSERT(start >= full_filename); 414 RTC_DCHECK(start >= full_filename);
414 memcpy(start, kLongPathPrefix, 7 * sizeof(wchar_t)); 415 memcpy(start, kLongPathPrefix, 7 * sizeof(wchar_t));
415 } else { 416 } else {
416 // Already in long-path form. 417 // Already in long-path form.
417 } 418 }
418 filename->assign(start); 419 filename->assign(start);
419 return true; 420 return true;
420 } 421 }
421 422
422 bool GetOsVersion(int* major, int* minor, int* build) { 423 bool GetOsVersion(int* major, int* minor, int* build) {
423 OSVERSIONINFO info = {0}; 424 OSVERSIONINFO info = {0};
(...skipping 24 matching lines...) Expand all
448 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); 449 *level = *GetSidSubAuthority(til->Label.Sid, count - 1);
449 ret = true; 450 ret = true;
450 } 451 }
451 } 452 }
452 CloseHandle(token); 453 CloseHandle(token);
453 } 454 }
454 return ret; 455 return ret;
455 } 456 }
456 457
457 } // namespace rtc 458 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/unixfilesystem.cc ('k') | webrtc/base/win32filesystem.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698