1. Список говнокодов пользователя Myxa

    Всего: 1

  2. Си / Говнокод #26828

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    /*
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                                                                             %
    %                                                                             %
    %                                                                             %
    +  N T M a p M e m o r y                                                      %
    %                                                                             %
    %                                                                             %
    %                                                                             %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    %  Mmap() emulates the Unix method of the same name.
    %
    %  The format of the NTMapMemory method is:
    %
    %    MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
    %      int access,int file,MagickOffsetType offset)
    %
    */
    MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
      int flags,int file,MagickOffsetType offset)
    {
      DWORD
        access_mode,
        high_length,
        high_offset,
        low_length,
        low_offset,
        protection_mode;
    
      HANDLE
        file_handle,
        map_handle;
    
      void
        *map;
    
      (void) address;
      access_mode=0;
      file_handle=INVALID_HANDLE_VALUE;
      low_length=(DWORD) (length & 0xFFFFFFFFUL);
      high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
      map_handle=INVALID_HANDLE_VALUE;
      map=(void *) NULL;
      low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
      high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
      protection_mode=0;
      if (protection & PROT_WRITE)
        {
          access_mode=FILE_MAP_WRITE;
          if (!(flags & MAP_PRIVATE))
            protection_mode=PAGE_READWRITE;
          else
            {
              access_mode=FILE_MAP_COPY;
              protection_mode=PAGE_WRITECOPY;
            }
        }
      else
        if (protection & PROT_READ)
          {
            access_mode=FILE_MAP_READ;
            protection_mode=PAGE_READONLY;
          }
      if ((file == -1) && (flags & MAP_ANONYMOUS))
        file_handle=INVALID_HANDLE_VALUE;
      else
        file_handle=(HANDLE) _get_osfhandle(file);
      map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
        low_length,0);
      if (map_handle)
        {
          map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
            length);
          CloseHandle(map_handle);
        }
      if (map == (void *) NULL)
        return((void *) ((char *) MAP_FAILED));
      return((void *) ((char *) map));
    }

    Мумуляция «mmap» в «Винде». Это даже работает, если пофиксить две строчки (кто угадает, какие именно, тому ничего).

    Отсюда:
    https://github.com/ImageMagick/ImageMagick/blob/master/MagickCore/nt-base.c

    Myxa, 30 Июля 2020

    Комментарии (29)