]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'public/getfilesize_64'
authorNick Mathewson <nickm@torproject.org>
Tue, 5 Jun 2012 15:10:42 +0000 (11:10 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 5 Jun 2012 15:10:42 +0000 (11:10 -0400)
Conflicts:
src/common/compat.c

The getfilesize change conflicted with the removal of file_handle
from the windows tor_mmap_t.

1  2 
src/common/compat.c

index 87fe84cb4bf6b1e61317de43c8531cccfd5def3f,00ebbe4c1af5b19c9e30a7dc012a4592d99a8530..334ea1b8b404d6920beedee200564cfabf4a6318
@@@ -228,40 -175,48 +228,48 @@@ tor_mmap_file(const char *filename
    TCHAR tfilename[MAX_PATH]= {0};
    tor_mmap_t *res = tor_malloc_zero(sizeof(tor_mmap_t));
    int empty = 0;
 -  res->file_handle = INVALID_HANDLE_VALUE;
 +  HANDLE file_handle = INVALID_HANDLE_VALUE;
+   DWORD size_low, size_high;
+   uint64_t real_size;
    res->mmap_handle = NULL;
  #ifdef UNICODE
    mbstowcs(tfilename,filename,MAX_PATH);
  #else
    strlcpy(tfilename,filename,MAX_PATH);
  #endif
 -  res->file_handle = CreateFile(tfilename,
 -                                GENERIC_READ, FILE_SHARE_READ,
 -                                NULL,
 -                                OPEN_EXISTING,
 -                                FILE_ATTRIBUTE_NORMAL,
 -                                0);
 +  file_handle = CreateFile(tfilename,
 +                           GENERIC_READ, FILE_SHARE_READ,
 +                           NULL,
 +                           OPEN_EXISTING,
 +                           FILE_ATTRIBUTE_NORMAL,
 +                           0);
  
 -  if (res->file_handle == INVALID_HANDLE_VALUE)
 +  if (file_handle == INVALID_HANDLE_VALUE)
      goto win_err;
  
-   res->size = GetFileSize(file_handle, NULL);
 -  size_low = GetFileSize(res->file_handle, &size_high);
++  size_low = GetFileSize(file_handle, &size_high);
  
-   if (res->size == 0) {
+   if (size_low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) {
+     log_warn(LD_FS,"Error getting size of \"%s\".",filename);
+     goto win_err;
+   }
+   if (size_low == 0 && size_high == 0) {
      log_info(LD_FS,"File \"%s\" is empty. Ignoring.",filename);
      empty = 1;
      goto err;
    }
+   real_size = (((uint64_t)size_high)<<32) | size_low;
+   if (real_size > SIZE_MAX) {
+     log_warn(LD_FS,"File \"%s\" is too big to map; not trying.",filename);
+     goto err;
+   }
+   res->size = real_size;
  
 -  res->mmap_handle = CreateFileMapping(res->file_handle,
 +  res->mmap_handle = CreateFileMapping(file_handle,
                                         NULL,
                                         PAGE_READONLY,
- #if SIZEOF_SIZE_T > 4
-                                        (res->base.size >> 32),
- #else
-                                        0,
- #endif
-                                        (res->size & 0xfffffffful),
+                                        size_high,
+                                        size_low,
                                         NULL);
    if (res->mmap_handle == NULL)
      goto win_err;