首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

open, ftruncate, m地图

2013-02-04 
open, ftruncate, mmapopensystem\core\init\property_service.candroid:fd open(/dev/__properties__

open, ftruncate, mmap
open
system\core\init\property_service.c
android:
fd = open("/dev/__properties__", O_RDWR | O_CREAT, 0600);


mingw:
    fd = open("c:\\__properties__", O_RDWR | O_CREAT, 0600);
if (fd < 0){
fd = creat("c:\\__properties__", O_RDWR | O_CREAT);
if (fd < 0){
printf("ERROR opening.\n\terror is:%s\n", strerror(errno));
return -1;

chmod("c:\\__properties__", 0600);
}



ftruncate
mingw
c:\mingw-4.6.1\include\unistd.h
__CRT_INLINE int ftruncate(int __fd, off_t __length)
{
  return _chsize (__fd, __length);
}




mmap
system\core\init\property_service.c
android:
    data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);


mingw:
nt-base.h:
#if !defined(mmap)
#  define mmap(address,length,protection,access,file,offset) \
  NTMapMemory(address,length,protection,access,file,offset)
#endif
nt-base.c:
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
+  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:
%
%    MagickExport void *NTMapMemory(char *address,size_t length,int protection,
%      int access,int file,MagickOffsetType offset)
%
*/
//MagickExport void *NTMapMemory(char *address,size_t length,int protection,
 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);
  //The high-order DWORD of the maximum size of the file mapping object. normally it should be 0, unless 
  //the file size is extremely big.
  //refer to MemoryMappedFile::map in https://raw.github.com/zimbatm/deb-mongodb/master/util/mmap_win.cpp  
//  high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
  high_length=0;
  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){
printf("ERROR CreateFileMapping.\n\terror is:%s\n", strerror(errno));
    return((void *) MAP_FAILED);
  }
  return((void *) ((char *) map));
} //void *NTMapMemory(char *address,size_t length,int protection,

热点排行