open, ftruncate, mmap, stat
来源:互联网 发布:域名劫持工具 编辑:程序博客网 时间:2024/05/20 23:03
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);
}
autually mingw can create with open.
c:\MinGW-4.7.1\include\fcntl.h
#define O_CREAT 0x0100 /* create and open file */
d:/linux/linuxkernel/WORKING_DIRECTORY/android-omap-20111108-gingerbread/dalvik/vm/analysis/DexPrepare.c:87:0: warning: "O_CREAT" redefined [enabled by default]
d:/linux/linuxkernel/WORKING_DIRECTORY/android-omap-20111108-gingerbread/bionic/libc/kernel/common/asm-generic/fcntl.h:22:0: note: this is the location of the previous definition
if O_CREAT is not correct(0x0100), open(cacheFileName, O_CREAT|O_RDWR, 0600) might not take effect.
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)
% doesn't support PROT_NONE on windows
*/
//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;
/*dwMaximumSizeLow [in]
*The low-order DWORD of the maximum size of the file mapping object.
*If this parameter and dwMaximumSizeHigh are 0 (zero),
* the maximum size of the file mapping object is equal to the current size of the file that hFile identifies.
* As sometimes the length is smaller than file size, which would cause error if the offset is larger than length,
* we take 0 as default */
// low_length=(DWORD) (length & 0xFFFFFFFFUL);
low_length=0;
//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);
high_offset=0;
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;
/*If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size
* for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters.
* In this scenario, CreateFileMapping creates a file mapping object of a specified size
* that is backed by the system paging file instead of by a file in the file system.*/
low_length=(DWORD) (length & 0xFFFFFFFFUL);
}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){
char errormsg[500];
sprintf(errormsg, "ERROR CreateFileMapping.\n\terror is:%s\n", strerror(errno));
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,
stat:
make sure the program is using the definition of struct stat in c:\mingw-4.7.1\include\sys\stat.h. u can try to rename stat.h to statm.h, and include it.
- open, ftruncate, mmap, stat
- ftruncate
- ftruncate
- ftruncate
- ftruncate()
- open,ioctl,mmap函数解释
- 文件映射mmap简单设置文件大小(lseek (ftruncate可以设置文件大小))__使用mmap即文件映射实现文件的快速复制代码
- ftruncate函数
- ftruncate()函数
- ftruncate函数
- ftruncate函数
- ftruncate函数
- 关于ftruncate()
- stat
- stat
- STAT
- Stat
- stat
- Linux下GCC生成和使用静态库和动态库详解(一)
- Linux下GCC生成和使用静态库和动态库详解(二)
- Cocoa2D 实现半透明暂停菜单
- 关于c盘里的文件夹
- 一个华为人辞职创业后的几个反思
- open, ftruncate, mmap, stat
- TextView属性
- 景深效果
- hdu 1558 Segment set(并查集+计算几何线段相交)
- 在Eclipse中查看JDK类库的源代码
- Python笔记(3)异常处理
- epay-8 多表查询,一维数组怎么放入二维数组??
- hive 全排序 优化
- 由pushViewController说起可能出线的各种死法