⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 target_generic_file.h

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 H
📖 第 1 页 / 共 2 页
字号:
/* target_generic_file - Native methods for file operations   Copyright (C) 1998, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. *//*Description: generic target defintions of file functionsSystems    : all*/#ifndef __TARGET_GENERIC_FILE__#define __TARGET_GENERIC_FILE__#ifdef __cplusplusextern "C" {#endif/* check if target_native_file.h included */#ifndef __TARGET_NATIVE_FILE__  #error Do NOT INCLUDE generic target files! Include the corresponding native target files instead!#endif/****************************** Includes *******************************//* do not move; needed here because of some macro definitions */#include "config.h"#include <stdlib.h>#include <assert.h>#include <fcntl.h>#include "target_native.h"#include "target_native_math_int.h"/****************** Conditional compilation switches *******************//***************************** Constants *******************************/#ifndef TARGET_NATIVE_FILE_FILEFLAG_NONE  #define TARGET_NATIVE_FILE_FILEFLAG_NONE 0#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE  #define TARGET_NATIVE_FILE_FILEFLAG_CREATE O_CREAT#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE  #define TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE (O_CREAT|O_EXCL)#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_READ  #define TARGET_NATIVE_FILE_FILEFLAG_READ O_RDONLY#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_WRITE  #define TARGET_NATIVE_FILE_FILEFLAG_WRITE O_WRONLY#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_READWRITE  #define TARGET_NATIVE_FILE_FILEFLAG_READWRITE O_RDWR#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE  #define TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE O_TRUNC#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_APPEND  #define TARGET_NATIVE_FILE_FILEFLAG_APPEND O_APPEND#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_SYNC  #if !defined (O_SYNC) && defined (O_FSYNC)    #define TARGET_NATIVE_FILE_FILEFLAG_SYNC O_FSYNC  #else    #define TARGET_NATIVE_FILE_FILEFLAG_SYNC O_SYNC  #endif#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_DSYNC  #ifdef O_DSYNC    #define TARGET_NATIVE_FILE_FILEFLAG_DSYNC 0  #else    #define TARGET_NATIVE_FILE_FILEFLAG_DSYNC TARGET_NATIVE_FILE_FILEFLAG_SYNC  #endif#endif#ifndef TARGET_NATIVE_FILE_FILEFLAG_BINARY  #define TARGET_NATIVE_FILE_FILEFLAG_BINARY O_BINARY#endif#ifndef TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL  #define TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)#endif#ifndef TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE   #define TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE (S_IRUSR | S_IWUSR)#endif#ifndef TARGET_NATIVE_FILE_FILEPERMISSION_READONLY  #define TARGET_NATIVE_FILE_FILEPERMISSION_READONLY (~(S_IWRITE|S_IWGRP|S_IWOTH))#endif/***************************** Datatypes *******************************//***************************** Variables *******************************//****************************** Macros *********************************//***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN* Purpose    : open a file* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : file is created if it does not exist\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN  #include <sys/types.h>  #include <sys/stat.h>  #include <fcntl.h>  #define TARGET_NATIVE_FILE_OPEN(filename,filedescriptor,flags,permissions,result) \    do { \      filedescriptor=open(filename, \                          flags, \                          permissions \                          ); \      if (filedescriptor >= 0) \        fcntl (filedescriptor,F_SETFD,FD_CLOEXEC); \      result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \   } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN_CREATE* Purpose    : create a file* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : file is created if it does not exist\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN_CREATE  #define TARGET_NATIVE_FILE_OPEN_CREATE(filename,filedescriptor,result) \    TARGET_NATIVE_FILE_OPEN(filename,\                            filedescriptor,\                            TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE, \                            TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \                            result \                           )#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN_READ* Purpose    : open an existing file for reading* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN_READ  #define TARGET_NATIVE_FILE_OPEN_READ(filename,filedescriptor,result) \    TARGET_NATIVE_FILE_OPEN(filename, \                            filedescriptor,\                            TARGET_NATIVE_FILE_FILEFLAG_READ, \                            TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \                            result \                           )#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN_WRITE* Purpose    : open an existing file for writing* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN_WRITE  #define TARGET_NATIVE_FILE_OPEN_WRITE(filename,filedescriptor,result) \    TARGET_NATIVE_FILE_OPEN(filename, \                            filedescriptor, \                            TARGET_NATIVE_FILE_FILEFLAG_WRITE, \                            TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \                            result \                           )#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN_READWRITE* Purpose    : create/open a file for reading/writing* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : file is created if it does not exist\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN_READWRITE  #define TARGET_NATIVE_FILE_OPEN_READWRITE(filename,filedescriptor,result) \    TARGET_NATIVE_FILE_OPEN(filename, \                            filedescriptor, \                            TARGET_NATIVE_FILE_FILEFLAG_READWRITE, \                            TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \                            result \                           )#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_OPEN_READWRITE* Purpose    : create/open a file for append* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : file is created if it does not exist\***********************************************************************/#ifndef TARGET_NATIVE_FILE_OPEN_APPEND  #define TARGET_NATIVE_FILE_OPEN_APPEND(filename,filedescriptor,result) \    TARGET_NATIVE_FILE_OPEN_APPEND(filename, \                                   filedescriptor, \                                   TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE|TARGET_NATIVE_FILE_FILEFLAG_APPEND, \                                   TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \                                   result \                                  )#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_CLOSE* Purpose    : close a file* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_CLOSE  #include <unistd.h>  #define TARGET_NATIVE_FILE_CLOSE(filedescriptor,result) \    do  { \      result=(close(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \   } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR* Purpose    : check if file-descriptor is valid* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR  #if   defined(HAVE_FCNTL)    #include <unistd.h>    #include <fcntl.h>    #define TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR(filedescriptor,result) \      do { \        result=(fcntl(filedescriptor,F_GETFL,0)!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \      } while(0)  #elif defined(HAVE_FSTAT)    #include <sys/types.h>    #include <sys/stat.h>    #include <unistd.h>    #define TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR(filedescriptor,result) \      do { \        struct stat __stat; \        \        result=(fstat(filedescriptor,&__stat)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \      } while(0)  #else    #error fcntl() nor fstat() available for checking if file descriptor is valid  #endif#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_TELL* Purpose    : get current file position* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_TELL  #include <sys/types.h>  #include <unistd.h>  #define TARGET_NATIVE_FILE_TELL(filedescriptor,offset,result) \    do { \      offset=lseek(filedescriptor,TARGET_NATIVE_MATH_INT_INT64_CONST_0,SEEK_CUR); \      result=((offset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \    } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_SEEK_BEGIN|CURRENT|END* Purpose    : set file position relativ to begin/current/end* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_SEEK_BEGIN  #include <sys/types.h>  #include <unistd.h>  #define TARGET_NATIVE_FILE_SEEK_BEGIN(filedescriptor,offset,newoffset,result) \    do { \      newoffset=lseek(filedescriptor,offset,SEEK_SET); \      result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \    } while (0)#endif#ifndef TARGET_NATIVE_FILE_SEEK_CURRENT  #include <sys/types.h>  #include <unistd.h>  #define TARGET_NATIVE_FILE_SEEK_CURRENT(filedescriptor,offset,newoffset,result) \    do { \      newoffset=lseek(filedescriptor,offset,SEEK_CUR); \      result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \    } while (0)#endif#ifndef TARGET_NATIVE_FILE_SEEK_END  #include <sys/types.h>  #include <unistd.h>  #define TARGET_NATIVE_FILE_SEEK_END(filedescriptor,offset,newoffset,result) \    do { \      newoffset=lseek(filedescriptor,offset,SEEK_END); \      result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \    } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_TRUNCATE* Purpose    : truncate a file* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_TRUNCATE  #include <unistd.h>  #define TARGET_NATIVE_FILE_TRUNCATE(filedescriptor,offset,result) \    do { \      result=(ftruncate(filedescriptor,offset)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \    } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_SIZE* Purpose    : get size of file (in bytes)* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_SIZE  #include <sys/types.h>  #include <sys/stat.h>  #include <unistd.h>  #define TARGET_NATIVE_FILE_SIZE(filedescriptor,length,result) \    do { \      struct stat __statBuffer; \      \      result=(fstat(filedescriptor,&__statBuffer)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \      length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size); \    } while (0)#endif/***********************************************************************\* Name       : TARGET_NATIVE_FILE_AVAILABLE* Purpose    : get available bytes for read* Input      : -* Output     : -* Return     : -* Side-effect: unknown* Notes      : -\***********************************************************************/#ifndef TARGET_NATIVE_FILE_AVAILABLE  #ifdef HAVE_SYS_IOCTL_H    #define BSD_COMP /* Get FIONREAD on Solaris2 */    #include <sys/ioctl.h>  #endif  #ifdef HAVE_SYS_FILIO_H /* Get FIONREAD on Solaris 2.5 */    #include <sys/filio.h>  #endif  #if defined (FIONREAD)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -