1 /* target_generic_file - Native methods for file operations
2 Copyright (C) 1998, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 Description: generic target defintions of file functions
43 #ifndef __TARGET_GENERIC_FILE__
44 #define __TARGET_GENERIC_FILE__
50 /* check if target_native_file.h included */
51 #ifndef __TARGET_NATIVE_FILE__
52 #error Do NOT INCLUDE generic target files! Include the corresponding native target files instead!
55 /****************************** Includes *******************************/
56 /* do not move; needed here because of some macro definitions */
63 #include "target_native.h"
64 #include "target_native_math_int.h"
66 /****************** Conditional compilation switches *******************/
68 /***************************** Constants *******************************/
69 #ifndef TARGET_NATIVE_FILE_FILEFLAG_NONE
70 #define TARGET_NATIVE_FILE_FILEFLAG_NONE 0
72 #ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE
73 #define TARGET_NATIVE_FILE_FILEFLAG_CREATE O_CREAT
75 #ifndef TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE
76 #define TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE (O_CREAT|O_EXCL)
78 #ifndef TARGET_NATIVE_FILE_FILEFLAG_READ
79 #define TARGET_NATIVE_FILE_FILEFLAG_READ O_RDONLY
81 #ifndef TARGET_NATIVE_FILE_FILEFLAG_WRITE
82 #define TARGET_NATIVE_FILE_FILEFLAG_WRITE O_WRONLY
84 #ifndef TARGET_NATIVE_FILE_FILEFLAG_READWRITE
85 #define TARGET_NATIVE_FILE_FILEFLAG_READWRITE O_RDWR
87 #ifndef TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE
88 #define TARGET_NATIVE_FILE_FILEFLAG_TRUNCATE O_TRUNC
90 #ifndef TARGET_NATIVE_FILE_FILEFLAG_APPEND
91 #define TARGET_NATIVE_FILE_FILEFLAG_APPEND O_APPEND
93 #ifndef TARGET_NATIVE_FILE_FILEFLAG_SYNC
94 #if !defined (O_SYNC) && defined (O_FSYNC)
95 #define TARGET_NATIVE_FILE_FILEFLAG_SYNC O_FSYNC
97 #define TARGET_NATIVE_FILE_FILEFLAG_SYNC O_SYNC
100 #ifndef TARGET_NATIVE_FILE_FILEFLAG_DSYNC
102 #define TARGET_NATIVE_FILE_FILEFLAG_DSYNC 0
104 #define TARGET_NATIVE_FILE_FILEFLAG_DSYNC TARGET_NATIVE_FILE_FILEFLAG_SYNC
107 #ifndef TARGET_NATIVE_FILE_FILEFLAG_BINARY
108 #define TARGET_NATIVE_FILE_FILEFLAG_BINARY O_BINARY
111 #ifndef TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL
112 #define TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
115 #ifndef TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE
116 #define TARGET_NATIVE_FILE_FILEPERMISSION_PRIVATE (S_IRUSR | S_IWUSR)
119 #ifndef TARGET_NATIVE_FILE_FILEPERMISSION_READONLY
120 #define TARGET_NATIVE_FILE_FILEPERMISSION_READONLY (~(S_IWRITE|S_IWGRP|S_IWOTH))
123 /***************************** Datatypes *******************************/
125 /***************************** Variables *******************************/
127 /****************************** Macros *********************************/
129 /***********************************************************************\
130 * Name : TARGET_NATIVE_FILE_OPEN
131 * Purpose : open a file
135 * Side-effect: unknown
136 * Notes : file is created if it does not exist
137 \***********************************************************************/
139 #ifndef TARGET_NATIVE_FILE_OPEN
140 #include <sys/types.h>
141 #include <sys/stat.h>
143 #define TARGET_NATIVE_FILE_OPEN(filename,filedescriptor,flags,permissions,result) \
145 filedescriptor=open(filename, \
149 if (filedescriptor >= 0) \
150 fcntl (filedescriptor,F_SETFD,FD_CLOEXEC); \
151 result=(filedescriptor>=0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
155 /***********************************************************************\
156 * Name : TARGET_NATIVE_FILE_OPEN_CREATE
157 * Purpose : create a file
161 * Side-effect: unknown
162 * Notes : file is created if it does not exist
163 \***********************************************************************/
165 #ifndef TARGET_NATIVE_FILE_OPEN_CREATE
166 #define TARGET_NATIVE_FILE_OPEN_CREATE(filename,filedescriptor,result) \
167 TARGET_NATIVE_FILE_OPEN(filename,\
169 TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE, \
170 TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \
175 /***********************************************************************\
176 * Name : TARGET_NATIVE_FILE_OPEN_READ
177 * Purpose : open an existing file for reading
181 * Side-effect: unknown
183 \***********************************************************************/
185 #ifndef TARGET_NATIVE_FILE_OPEN_READ
186 #define TARGET_NATIVE_FILE_OPEN_READ(filename,filedescriptor,result) \
187 TARGET_NATIVE_FILE_OPEN(filename, \
189 TARGET_NATIVE_FILE_FILEFLAG_READ, \
190 TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \
195 /***********************************************************************\
196 * Name : TARGET_NATIVE_FILE_OPEN_WRITE
197 * Purpose : open an existing file for writing
201 * Side-effect: unknown
203 \***********************************************************************/
205 #ifndef TARGET_NATIVE_FILE_OPEN_WRITE
206 #define TARGET_NATIVE_FILE_OPEN_WRITE(filename,filedescriptor,result) \
207 TARGET_NATIVE_FILE_OPEN(filename, \
209 TARGET_NATIVE_FILE_FILEFLAG_WRITE, \
210 TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \
215 /***********************************************************************\
216 * Name : TARGET_NATIVE_FILE_OPEN_READWRITE
217 * Purpose : create/open a file for reading/writing
221 * Side-effect: unknown
222 * Notes : file is created if it does not exist
223 \***********************************************************************/
225 #ifndef TARGET_NATIVE_FILE_OPEN_READWRITE
226 #define TARGET_NATIVE_FILE_OPEN_READWRITE(filename,filedescriptor,result) \
227 TARGET_NATIVE_FILE_OPEN(filename, \
229 TARGET_NATIVE_FILE_FILEFLAG_READWRITE, \
230 TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \
235 /***********************************************************************\
236 * Name : TARGET_NATIVE_FILE_OPEN_READWRITE
237 * Purpose : create/open a file for append
241 * Side-effect: unknown
242 * Notes : file is created if it does not exist
243 \***********************************************************************/
245 #ifndef TARGET_NATIVE_FILE_OPEN_APPEND
246 #define TARGET_NATIVE_FILE_OPEN_APPEND(filename,filedescriptor,result) \
247 TARGET_NATIVE_FILE_OPEN_APPEND(filename, \
249 TARGET_NATIVE_FILE_FILEFLAG_CREATE_FORCE|TARGET_NATIVE_FILE_FILEFLAG_APPEND, \
250 TARGET_NATIVE_FILE_FILEPERMISSION_NORMAL, \
255 /***********************************************************************\
256 * Name : TARGET_NATIVE_FILE_CLOSE
257 * Purpose : close a file
261 * Side-effect: unknown
263 \***********************************************************************/
265 #ifndef TARGET_NATIVE_FILE_CLOSE
267 #define TARGET_NATIVE_FILE_CLOSE(filedescriptor,result) \
269 result=(close(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
273 /***********************************************************************\
274 * Name : TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR
275 * Purpose : check if file-descriptor is valid
279 * Side-effect: unknown
281 \***********************************************************************/
283 #ifndef TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR
284 #if defined(HAVE_FCNTL)
287 #define TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR(filedescriptor,result) \
289 result=(fcntl(filedescriptor,F_GETFL,0)!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
291 #elif defined(HAVE_FSTAT)
292 #include <sys/types.h>
293 #include <sys/stat.h>
295 #define TARGET_NATIVE_FILE_VALID_FILE_DESCRIPTOR(filedescriptor,result) \
297 struct stat __stat; \
299 result=(fstat(filedescriptor,&__stat)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
302 #error fcntl() nor fstat() available for checking if file descriptor is valid
306 /***********************************************************************\
307 * Name : TARGET_NATIVE_FILE_TELL
308 * Purpose : get current file position
312 * Side-effect: unknown
314 \***********************************************************************/
316 #ifndef TARGET_NATIVE_FILE_TELL
317 #include <sys/types.h>
319 #define TARGET_NATIVE_FILE_TELL(filedescriptor,offset,result) \
321 offset=lseek(filedescriptor,TARGET_NATIVE_MATH_INT_INT64_CONST_0,SEEK_CUR); \
322 result=((offset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
326 /***********************************************************************\
327 * Name : TARGET_NATIVE_FILE_SEEK_BEGIN|CURRENT|END
328 * Purpose : set file position relativ to begin/current/end
332 * Side-effect: unknown
334 \***********************************************************************/
336 #ifndef TARGET_NATIVE_FILE_SEEK_BEGIN
337 #include <sys/types.h>
339 #define TARGET_NATIVE_FILE_SEEK_BEGIN(filedescriptor,offset,newoffset,result) \
341 newoffset=lseek(filedescriptor,offset,SEEK_SET); \
342 result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
345 #ifndef TARGET_NATIVE_FILE_SEEK_CURRENT
346 #include <sys/types.h>
348 #define TARGET_NATIVE_FILE_SEEK_CURRENT(filedescriptor,offset,newoffset,result) \
350 newoffset=lseek(filedescriptor,offset,SEEK_CUR); \
351 result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
354 #ifndef TARGET_NATIVE_FILE_SEEK_END
355 #include <sys/types.h>
357 #define TARGET_NATIVE_FILE_SEEK_END(filedescriptor,offset,newoffset,result) \
359 newoffset=lseek(filedescriptor,offset,SEEK_END); \
360 result=((newoffset)!=(off_t)-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
364 /***********************************************************************\
365 * Name : TARGET_NATIVE_FILE_TRUNCATE
366 * Purpose : truncate a file
370 * Side-effect: unknown
372 \***********************************************************************/
374 #ifndef TARGET_NATIVE_FILE_TRUNCATE
376 #define TARGET_NATIVE_FILE_TRUNCATE(filedescriptor,offset,result) \
378 result=(ftruncate(filedescriptor,offset)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
382 /***********************************************************************\
383 * Name : TARGET_NATIVE_FILE_SIZE
384 * Purpose : get size of file (in bytes)
388 * Side-effect: unknown
390 \***********************************************************************/
392 #ifndef TARGET_NATIVE_FILE_SIZE
393 #include <sys/types.h>
394 #include <sys/stat.h>
396 #define TARGET_NATIVE_FILE_SIZE(filedescriptor,length,result) \
398 struct stat __statBuffer; \
400 result=(fstat(filedescriptor,&__statBuffer)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
401 length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size); \
405 /***********************************************************************\
406 * Name : TARGET_NATIVE_FILE_AVAILABLE
407 * Purpose : get available bytes for read
411 * Side-effect: unknown
413 \***********************************************************************/
415 #ifndef TARGET_NATIVE_FILE_AVAILABLE
416 #ifdef HAVE_SYS_IOCTL_H
417 #define BSD_COMP /* Get FIONREAD on Solaris2 */
418 #include <sys/ioctl.h>
420 #ifdef HAVE_SYS_FILIO_H /* Get FIONREAD on Solaris 2.5 */
421 #include <sys/filio.h>
423 #if defined (FIONREAD)
424 #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
428 result=(ioctl(filedescriptor,FIONREAD,(char*)&__n)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
429 length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__n); \
431 #elif defined(HAVE_FSTAT)
432 #include <sys/types.h>
433 #include <sys/stat.h>
435 #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
437 struct stat __statBuffer; \
442 if ((fstat(filedescriptor,&__statBuffer)==0) && S_ISREG(__statBuffer.st_mode)) \
444 __n=(lseek(filedescriptor,0,SEEK_CUR)); \
447 length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size-__n); \
448 result=TARGET_NATIVE_OK; \
452 result=TARGET_NATIVE_ERROR; \
457 result=TARGET_NATIVE_ERROR; \
460 #elif defined(HAVE_SELECT)
462 #include <sys/select.h>
463 #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
465 fd_set __filedescriptset; \
466 struct timeval __timeval; \
470 FD_ZERO(&__filedescriptset); \
471 FD_SET(filedescriptor,&__filedescriptset); \
472 memset(&__timeval,0,sizeof(__timeval)); \
473 switch (select(filedescriptor+1,&__filedescriptset,NULL,NULL,&__timeval)==0) \
475 case -1: result=TARGET_NATIVE_ERROR; break; \
476 case 0: length=JNI_JLONG_CONST_0; result=TARGET_NATIVE_OK; break; \
477 default: length=JNI_JLONG_CONST_1; result=TARGET_NATIVE_OK; break; \
481 #define TARGET_NATIVE_FILE_AVAILABLE(filedescriptor,length,result) \
483 errno=TARGET_NATIVE_ERROR_OPERATION_NOT_PERMITTED; \
485 result=TARGET_NATIVE_ERROR; \
490 /***********************************************************************\
491 * Name : TARGET_NATIVE_FILE_READ|WRITE
492 * Purpose : read/write from/to frile
496 * Side-effect: unknown
498 \***********************************************************************/
500 #ifndef TARGET_NATIVE_FILE_READ
502 #define TARGET_NATIVE_FILE_READ(filedescriptor,buffer,length,bytesRead,result) \
504 bytesRead=read(filedescriptor,buffer,length); \
505 result=(bytesRead!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
508 #ifndef TARGET_NATIVE_FILE_WRITE
510 #define TARGET_NATIVE_FILE_WRITE(filedescriptor,buffer,length,bytesWritten,result) \
512 bytesWritten=write(filedescriptor,buffer,length); \
513 result=(bytesWritten!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
517 /***********************************************************************\
518 * Name : TARGET_NATIVE_FILE_SET_MODE_READONLY
519 * Purpose : set file mode to read-only
523 * Side-effect: unknown
525 \***********************************************************************/
527 #ifndef TARGET_NATIVE_FILE_SET_MODE_READONLY
528 #include <sys/types.h>
529 #include <sys/stat.h>
531 #define TARGET_NATIVE_FILE_SET_MODE_READONLY(filename,result) \
533 struct stat __statBuffer; \
535 if (stat(filename,&__statBuffer)==0) { \
536 result=(chmod(filename,__statBuffer.st_mode & TARGET_NATIVE_FILE_FILEPERMISSION_READONLY)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
538 result=TARGET_NATIVE_ERROR; \
543 /***********************************************************************\
544 * Name : TARGET_NATIVE_FILE_EXISTS
545 * Purpose : check if file exists
549 * Side-effect: unknown
551 \***********************************************************************/
553 #ifndef TARGET_NATIVE_FILE_EXISTS
554 #include <sys/types.h>
555 #include <sys/stat.h>
557 #define TARGET_NATIVE_FILE_EXISTS(filename,result) \
559 struct stat __statBuffer; \
561 result=(stat(filename,&__statBuffer)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
565 /***********************************************************************\
566 * Name : TARGET_NATIVE_FILE_IS_FILE
567 * Purpose : check if directory entry is a file
571 * Side-effect: unknown
573 \***********************************************************************/
575 #ifndef TARGET_NATIVE_FILE_IS_FILE
576 #include <sys/types.h>
577 #include <sys/stat.h>
579 #define TARGET_NATIVE_FILE_IS_FILE(filename,result) \
581 struct stat __statBuffer; \
583 result=((stat(filename,&__statBuffer)==0) && (S_ISREG(__statBuffer.st_mode)))?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
587 /***********************************************************************\
588 * Name : TARGET_NATIVE_FILE_IS_DIRECTORY
589 * Purpose : check if directory entry is a directory
593 * Side-effect: unknown
595 \***********************************************************************/
597 #ifndef TARGET_NATIVE_FILE_IS_DIRECTORY
598 #include <sys/types.h>
599 #include <sys/stat.h>
601 #define TARGET_NATIVE_FILE_IS_DIRECTORY(filename,result) \
603 struct stat __statBuffer; \
605 result=((stat(filename,&__statBuffer)==0) && (S_ISDIR(__statBuffer.st_mode)))?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
609 /***********************************************************************\
610 * Name : TARGET_NATIVE_FILE_GET_LAST_MODIFIED
611 * Purpose : get last modification time of file (milliseconds)
615 * Side-effect: unknown
617 \***********************************************************************/
619 #ifndef TARGET_NATIVE_FILE_GET_LAST_MODIFIED
620 #include <sys/types.h>
621 #include <sys/stat.h>
623 #define TARGET_NATIVE_FILE_GET_LAST_MODIFIED(filename,time,result) \
625 struct stat __statBuffer; \
627 time=TARGET_NATIVE_MATH_INT_INT64_CONST_0; \
628 if (stat(filename,&__statBuffer)==0) { \
629 time=TARGET_NATIVE_MATH_INT_INT64_MUL(TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_mtime), \
630 TARGET_NATIVE_MATH_INT_INT32_TO_INT64(1000) \
632 result=TARGET_NATIVE_OK; \
634 result=TARGET_NATIVE_ERROR; \
639 /***********************************************************************\
640 * Name : TARGET_NATIVE_FILE_SET_LAST_MODIFIED
641 * Purpose : set last modification time of file (milliseconds)
645 * Side-effect: unknown
647 \***********************************************************************/
649 #ifndef TARGET_NATIVE_FILE_SET_LAST_MODIFIED
650 #include <sys/types.h>
651 #include <sys/stat.h>
655 #elif HAVE_SYS_UTIME_H
656 #include <sys/utime.h>
658 #error utime.h not found. Please check configuration.
660 #define TARGET_NATIVE_FILE_SET_LAST_MODIFIED(filename,time,result) \
662 struct stat __statBuffer; \
663 struct utimbuf __utimeBuffer; \
665 if (stat(filename,&__statBuffer)==0) { \
666 __utimeBuffer.actime =__statBuffer.st_atime; \
667 __utimeBuffer.modtime=TARGET_NATIVE_MATH_INT_INT64_TO_INT32(TARGET_NATIVE_MATH_INT_INT64_DIV(time, \
668 TARGET_NATIVE_MATH_INT_INT32_TO_INT64(1000) \
671 result=(utime(filename,&__utimeBuffer)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
673 result=TARGET_NATIVE_ERROR; \
678 /***********************************************************************\
679 * Name : TARGET_NATIVE_FILE_DELETE
680 * Purpose : delete a file,link or directory
684 * Side-effect: unknown
686 \***********************************************************************/
688 #ifndef TARGET_NATIVE_FILE_DELETE
689 #define TARGET_NATIVE_FILE_DELETE(filename,result) \
691 result=((unlink(filename)==0) || (rmdir(filename)==0))?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
695 /***********************************************************************\
696 * Name : TARGET_NATIVE_FILE_RENAME
697 * Purpose : delete a file, link or directory
701 * Side-effect: unknown
703 \***********************************************************************/
705 #ifndef TARGET_NATIVE_FILE_RENAME
706 #define TARGET_NATIVE_FILE_RENAME(oldfilename,newfilename,result) \
708 result=(rename(oldfilename,newfilename)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
712 /***********************************************************************\
713 * Name : TARGET_NATIVE_FILE_MAKE_DIR
714 * Purpose : create new directory
715 * Input : name - directory name
716 * Output : result - 1 if successful, 0 otherwise
718 * Side-effect: unknown
720 \***********************************************************************/
722 #ifndef TARGET_NATIVE_FILE_MAKE_DIR
723 #include <sys/stat.h>
724 #define TARGET_NATIVE_FILE_MAKE_DIR(name,result) \
726 result=((mkdir(name,(S_IRWXO|S_IRWXG|S_IRWXU))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR); \
730 /***********************************************************************\
731 * Name : TARGET_NATIVE_FILE_GET_CWD
732 * Purpose : get current working directory
736 * Side-effect: unknown
738 \***********************************************************************/
740 #ifndef TARGET_NATIVE_FILE_GET_CWD
742 #define TARGET_NATIVE_FILE_GET_CWD(path,maxPathLength,result) \
744 result=(getcwd(path,maxPathLength)!=NULL)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
748 /***********************************************************************\
749 * Name : TARGET_NATIVE_FILE_OPEN_DIR
750 * Purpose : open directory for reading entries.
752 * Output : handle - handle if not error, NULL otherwise
754 * Side-effect: unknown
756 \***********************************************************************/
758 #ifndef TARGET_NATIVE_FILE_OPEN_DIR
759 #include <sys/types.h>
761 #define TARGET_NATIVE_FILE_OPEN_DIR(filename,handle,result) \
763 handle=(void*)opendir(filename); \
764 result=(handle!=NULL)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
768 /***********************************************************************\
769 * Name : TARGET_NATIVE_FILE_CLOSE_DIR
770 * Purpose : close directory
774 * Side-effect: unknown
776 \***********************************************************************/
778 #ifndef TARGET_NATIVE_FILE_CLOSE_DIR
779 #include <sys/types.h>
781 #define TARGET_NATIVE_FILE_CLOSE_DIR(handle,result) \
783 closedir((DIR*)handle); \
784 result=TARGET_NATIVE_OK; \
788 /***********************************************************************\
789 * Name : TARGET_NATIVE_FILE_READ_DIR
790 * Purpose : read directory entry
794 * Side-effect: unknown
796 \***********************************************************************/
798 /* XXX ??? name als buffer? */
799 #ifndef TARGET_NATIVE_FILE_READ_DIR
800 #include <sys/types.h>
802 #define TARGET_NATIVE_FILE_READ_DIR(handle,name,result) \
804 struct dirent *__direntBuffer; \
808 __direntBuffer=readdir((DIR*)handle); \
809 if (__direntBuffer!=NULL) { \
810 name=__direntBuffer->d_name; \
811 result=TARGET_NATIVE_OK; \
813 result=TARGET_NATIVE_ERROR; \
818 /***********************************************************************\
819 * Name : TARGET_NATIVE_FILE_FSYNC
820 * Purpose : do filesystem sync
824 * Side-effect: unknown
826 \***********************************************************************/
828 #ifndef TARGET_NATIVE_FILE_FSYNC
829 #define TARGET_NATIVE_FILE_FSYNC(filedescriptor,result) \
831 result=(fsync(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
835 /***************************** Functions *******************************/
841 #endif /* __TARGET_GENERIC_FILE__ */