64 |
/****************** Conditional compilation switches *******************/ |
/****************** Conditional compilation switches *******************/ |
65 |
|
|
66 |
/***************************** Constants *******************************/ |
/***************************** Constants *******************************/ |
67 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_NONE |
68 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_NONE 0 |
69 |
|
#endif |
70 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE |
71 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_CREATE O_CREAT |
72 |
|
#endif |
73 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE |
74 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE (O_CREAT|O_EXCL) |
75 |
|
#endif |
76 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_READ |
77 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_READ O_RDONLY |
78 |
|
#endif |
79 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_WRITE |
80 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_WRITE O_WRONLY |
81 |
|
#endif |
82 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_READWRITE |
83 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_READWRITE O_RDWR |
84 |
|
#endif |
85 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE |
86 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE O_TRUNC |
87 |
|
#endif |
88 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_APPEND |
89 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_APPEND O_APPEND |
90 |
|
#endif |
91 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_SYNC |
92 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_SYNC O_SYNC |
93 |
|
#endif |
94 |
|
#ifndef TARGET_NATIVE_FILE_FILEFLAG_DSYNC |
95 |
|
#ifdef O_DSYNC |
96 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_DSYNC 0 |
97 |
|
#else |
98 |
|
#define TARGET_NATIVE_FILE_FILEFLAG_DSYNC TARGET_NATIVE_FILE_FILEFLAG_SYNC |
99 |
|
#endif |
100 |
|
#endif |
101 |
|
|
102 |
|
#ifndef TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL |
103 |
|
#define TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) |
104 |
|
#endif |
105 |
|
|
106 |
|
#ifndef TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE |
107 |
|
#define TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE (S_IRUSR | S_IWUSR) |
108 |
|
#endif |
109 |
|
|
110 |
/***************************** Datatypes *******************************/ |
/***************************** Datatypes *******************************/ |
111 |
|
|
114 |
/****************************** Macros *********************************/ |
/****************************** Macros *********************************/ |
115 |
|
|
116 |
/***********************************************************************\ |
/***********************************************************************\ |
117 |
* Name : TARGET_NATIVE_FILE_OPEN_CREATE |
* Name : TARGET_NATIVE_FILE_OPEN |
118 |
* Purpose : create a file |
* Purpose : open a file |
119 |
* Input : - |
* Input : - |
120 |
* Output : - |
* Output : - |
121 |
* Return : - |
* Return : - |
123 |
* Notes : file is created if it does not exist |
* Notes : file is created if it does not exist |
124 |
\***********************************************************************/ |
\***********************************************************************/ |
125 |
|
|
126 |
#ifndef TARGET_NATIVE_FILE_OPEN_CREATE |
#ifndef TARGET_NATIVE_FILE_OPEN |
127 |
#include <sys/types.h> |
#include <sys/types.h> |
128 |
#include <sys/stat.h> |
#include <sys/stat.h> |
129 |
#include <fcntl.h> |
#include <fcntl.h> |
130 |
#define TARGET_NATIVE_FILE_OPEN_CREATE(filename,filedescriptor,result) \ |
#define TARGET_NATIVE_FILE_OPEN(filename,filedescriptor,flags,permissions,result) \ |
131 |
do { \ |
do { \ |
132 |
filedescriptor=open(filename,O_CREAT|O_EXCL|O_RDWR,0777); \ |
filedescriptor=open(filename, \ |
133 |
|
flags, \ |
134 |
|
permissions \ |
135 |
|
); \ |
136 |
result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
137 |
} while (0) |
} while (0) |
138 |
#endif |
#endif |
139 |
|
|
140 |
/***********************************************************************\ |
/***********************************************************************\ |
141 |
|
* Name : TARGET_NATIVE_FILE_OPEN_CREATE |
142 |
|
* Purpose : create a file |
143 |
|
* Input : - |
144 |
|
* Output : - |
145 |
|
* Return : - |
146 |
|
* Side-effect: unknown |
147 |
|
* Notes : file is created if it does not exist |
148 |
|
\***********************************************************************/ |
149 |
|
|
150 |
|
#ifndef TARGET_NATIVE_FILE_OPEN_CREATE |
151 |
|
#define TARGET_NATIVE_FILE_OPEN_CREATE(filename,filedescriptor,result) \ |
152 |
|
TARGET_NATIVE_FILE_OPEN(filename,\ |
153 |
|
filedescriptor,\ |
154 |
|
TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE, \ |
155 |
|
TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \ |
156 |
|
result \ |
157 |
|
) |
158 |
|
#endif |
159 |
|
|
160 |
|
/***********************************************************************\ |
161 |
* Name : TARGET_NATIVE_FILE_OPEN_READ |
* Name : TARGET_NATIVE_FILE_OPEN_READ |
162 |
* Purpose : open an existing file for reading |
* Purpose : open an existing file for reading |
163 |
* Input : - |
* Input : - |
168 |
\***********************************************************************/ |
\***********************************************************************/ |
169 |
|
|
170 |
#ifndef TARGET_NATIVE_FILE_OPEN_READ |
#ifndef TARGET_NATIVE_FILE_OPEN_READ |
|
#include <sys/types.h> |
|
|
#include <sys/stat.h> |
|
|
#include <fcntl.h> |
|
171 |
#define TARGET_NATIVE_FILE_OPEN_READ(filename,filedescriptor,result) \ |
#define TARGET_NATIVE_FILE_OPEN_READ(filename,filedescriptor,result) \ |
172 |
do { \ |
TARGET_NATIVE_FILE_OPEN(filename, \ |
173 |
filedescriptor=open(filename,O_RDONLY); \ |
filedescriptor,\ |
174 |
result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
TARGET_NATIVE_FILE_FILEFLAG_READ, \ |
175 |
} while (0) |
TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \ |
176 |
|
result \ |
177 |
|
) |
178 |
|
#endif |
179 |
|
|
180 |
|
/***********************************************************************\ |
181 |
|
* Name : TARGET_NATIVE_FILE_OPEN_WRITE |
182 |
|
* Purpose : open an existing file for writing |
183 |
|
* Input : - |
184 |
|
* Output : - |
185 |
|
* Return : - |
186 |
|
* Side-effect: unknown |
187 |
|
* Notes : - |
188 |
|
\***********************************************************************/ |
189 |
|
|
190 |
|
#ifndef TARGET_NATIVE_FILE_OPEN_WRITE |
191 |
|
#define TARGET_NATIVE_FILE_OPEN_WRITE(filename,filedescriptor,result) \ |
192 |
|
TARGET_NATIVE_FILE_OPEN(filename, \ |
193 |
|
filedescriptor, \ |
194 |
|
TARGET_NATIVE_FILE_FILEFLAG_WRITE, \ |
195 |
|
TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \ |
196 |
|
result \ |
197 |
|
) |
198 |
#endif |
#endif |
199 |
|
|
200 |
/***********************************************************************\ |
/***********************************************************************\ |
208 |
\***********************************************************************/ |
\***********************************************************************/ |
209 |
|
|
210 |
#ifndef TARGET_NATIVE_FILE_OPEN_READWRITE |
#ifndef TARGET_NATIVE_FILE_OPEN_READWRITE |
|
#include <sys/types.h> |
|
|
#include <sys/stat.h> |
|
|
#include <fcntl.h> |
|
211 |
#define TARGET_NATIVE_FILE_OPEN_READWRITE(filename,filedescriptor,result) \ |
#define TARGET_NATIVE_FILE_OPEN_READWRITE(filename,filedescriptor,result) \ |
212 |
do { \ |
TARGET_NATIVE_FILE_OPEN(filename, \ |
213 |
filedescriptor=open(filename,O_RDWR,0666); \ |
filedescriptor, \ |
214 |
result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
TARGET_NATIVE_FILE_FILEFLAG_READWRITE, \ |
215 |
} while (0) |
TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \ |
216 |
|
result \ |
217 |
|
) |
218 |
|
#endif |
219 |
|
|
220 |
|
/***********************************************************************\ |
221 |
|
* Name : TARGET_NATIVE_FILE_OPEN_READWRITE |
222 |
|
* Purpose : create/open a file for append |
223 |
|
* Input : - |
224 |
|
* Output : - |
225 |
|
* Return : - |
226 |
|
* Side-effect: unknown |
227 |
|
* Notes : file is created if it does not exist |
228 |
|
\***********************************************************************/ |
229 |
|
|
230 |
|
#ifndef TARGET_NATIVE_FILE_OPEN_APPEND |
231 |
|
#define TARGET_NATIVE_FILE_OPEN_APPEND(filename,filedescriptor,result) \ |
232 |
|
TARGET_NATIVE_FILE_OPEN_APPEND(filename, \ |
233 |
|
filedescriptor, \ |
234 |
|
TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE|TARGET_NATIVE_FILE_FILEFLAG_APPEND, \ |
235 |
|
TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \ |
236 |
|
result \ |
237 |
|
) |
238 |
#endif |
#endif |
239 |
|
|
240 |
/***********************************************************************\ |
/***********************************************************************\ |
372 |
#endif |
#endif |
373 |
|
|
374 |
/***********************************************************************\ |
/***********************************************************************\ |
375 |
|
* Name : TARGET_NATIVE_FILE_AVAILABLE |
376 |
|
* Purpose : get available bytes for read |
377 |
|
* Input : - |
378 |
|
* Output : - |
379 |
|
* Return : - |
380 |
|
* Side-effect: unknown |
381 |
|
* Notes : - |
382 |
|
\***********************************************************************/ |
383 |
|
|
384 |
|
#ifndef TARGET_NATIVE_FILE_AVAILABLE |
385 |
|
#if defined(FIONREAD) |
386 |
|
#include <sys/ioctl.h> |
387 |
|
#ifdef HAVE_SYS_IOCTL_H |
388 |
|
#define BSD_COMP /* Get FIONREAD on Solaris2 */ |
389 |
|
#include <sys/ioctl.h> |
390 |
|
#endif |
391 |
|
#ifdef HAVE_SYS_FILIO_H /* Get FIONREAD on Solaris 2.5 */ |
392 |
|
#include <sys/filio.h> |
393 |
|
#endif |
394 |
|
#define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \ |
395 |
|
do { \ |
396 |
|
ssize_t __n; \ |
397 |
|
\ |
398 |
|
result=(ioctl(filedescriptor,FIONREAD,(char*)&n)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
399 |
|
length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(n); \ |
400 |
|
} while (0) |
401 |
|
#elif defined(HAVE_FSTAT) |
402 |
|
#include <sys/types.h> |
403 |
|
#include <sys/stat.h> |
404 |
|
#include <unistd.h> |
405 |
|
#define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \ |
406 |
|
do { \ |
407 |
|
struct stat __statBuffer; \ |
408 |
|
off_t __n; \ |
409 |
|
\ |
410 |
|
length=0; \ |
411 |
|
\ |
412 |
|
if ((fstat(filedescriptor,&__statBuffer)==0) && S_ISREG(__statBuffer.st_mode)) \ |
413 |
|
{ \ |
414 |
|
__n=(lseek(filedescriptor,0,SEEK_CUR)); \ |
415 |
|
if (__n!=-1) \ |
416 |
|
{ \ |
417 |
|
length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size-__n); \ |
418 |
|
result=TARGET_NATIVE_OK; \ |
419 |
|
} \ |
420 |
|
else \ |
421 |
|
{ \ |
422 |
|
result=TARGET_NATIVE_ERROR; \ |
423 |
|
} \ |
424 |
|
} \ |
425 |
|
else \ |
426 |
|
{ \ |
427 |
|
result=TARGET_NATIVE_ERROR; \ |
428 |
|
} \ |
429 |
|
} while (0) |
430 |
|
#elif defined(HAVE_SELECT) |
431 |
|
#include <string.h> |
432 |
|
#include <sys/select.h> |
433 |
|
#define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \ |
434 |
|
do { \ |
435 |
|
fd_set __filedescriptset; \ |
436 |
|
struct timeval __timeval; \ |
437 |
|
\ |
438 |
|
length=0; \ |
439 |
|
\ |
440 |
|
FD_ZERO(&__filedescriptset); \ |
441 |
|
FD_SET(filedescriptor,&__filedescriptset); \ |
442 |
|
memset(&__timeval,0,sizeof(__timeval)); \ |
443 |
|
switch (select(filedescriptor+1,&__filedescriptset,NULL,NULL,&__timeval)==0) \ |
444 |
|
{ \ |
445 |
|
case -1: result=TARGET_NATIVE_ERROR; break; \ |
446 |
|
case 0: length=JNI_JLONG_CONST_0; result=TARGET_NATIVE_OK; break; \ |
447 |
|
default: length=JNI_JLONG_CONST_1; result=TARGET_NATIVE_OK; break; \ |
448 |
|
} \ |
449 |
|
} while (0) |
450 |
|
#else |
451 |
|
#define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \ |
452 |
|
do { \ |
453 |
|
errno=TARGET_NATIVE_ERROR_OPERATION_NOT_PERMITTED; \ |
454 |
|
length=0; \ |
455 |
|
result=TARGET_NATIVE_ERROR; \ |
456 |
|
} while (0) |
457 |
|
#endif |
458 |
|
#endif |
459 |
|
|
460 |
|
/***********************************************************************\ |
461 |
* Name : TARGET_NATIVE_FILE_READ|WRITE |
* Name : TARGET_NATIVE_FILE_READ|WRITE |
462 |
* Purpose : read/write from/to frile |
* Purpose : read/write from/to frile |
463 |
* Input : - |
* Input : - |