17 #define _XOPEN_SOURCE 700
25 #include <sys/types.h>
31 #if defined(_SION_SIONFWD)
32 #include <sionfwd/client.h>
37 #include "sion_error_handler.h"
41 #ifdef _SION_IME_NATIVE
42 #include "ime_native.h"
74 if(!sion_fileptr->fileptr) {
76 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,
"error: could not open file (ANSI), %s %d %d, aborting ...\n", fname, flags, addflags);
99 if(sion_fileptr->fd<0) {
101 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,
"error: could not open file (POSIX), %s %d %d, aborting ...\n", fname, flags, addflags);
105 return(sion_fileptr);
107 #if defined(_SION_SIONFWD)
108 else if (flags & SION_FILE_FLAG_SIONFWD) {
110 sion_fileptr->flags |= SION_FILE_FLAG_SIONFWD;
116 sion_fileptr->fd=_sion_file_open_sionfwd_write_create(fname,addflags);
118 sion_fileptr->fd=_sion_file_open_sionfwd_write_existing(fname,addflags);
122 sion_fileptr->fd=_sion_file_open_sionfwd_read(fname,addflags);
126 if(sion_fileptr->fd == -1) {
128 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,
"error: could not open file (SIONFWD), %s %d %d, aborting ...\n", fname, flags, addflags);
132 return(sion_fileptr);
135 #ifdef _SION_IME_NATIVE
136 else if (flags & SION_FILE_FLAG_IME_NATIVE) {
138 sion_fileptr->flags |= SION_FILE_FLAG_IME_NATIVE;
144 sion_fileptr->fd = _sion_file_open_ime_native_write_create(fname, addflags);
146 sion_fileptr->fd = _sion_file_open_ime_native_write_existing(fname, addflags);
150 sion_fileptr->fd = _sion_file_open_ime_native_read(fname, addflags);
154 if (sion_fileptr->fd < 0) {
156 _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_WARN,
"error: could not open file (IME native), %s %d %d, aborting ...\n", fname,
166 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,
"internal error: unknown open type, %s %d %d, aborting ...\n", fname, flags, addflags);
171 #define DFUNCTION "_sion_file_close"
179 if (NULL == sion_fileptr)
return SION_NOT_SUCCESS;
185 sion_fileptr->second_fileptr=NULL;
188 sion_fileptr->fileptr=NULL;
192 #if defined(_SION_SIONFWD)
193 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
194 rc=_sion_file_close_sionfwd(sion_fileptr->fd);
197 #ifdef _SION_IME_NATIVE
198 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
199 rc = _sion_file_close_ime_native(sion_fileptr->fd);
203 rc = SION_NOT_SUCCESS;
206 DPRINTFP((32, DFUNCTION, -1,
"free now fileptr=%x %d rc=%d\n",sion_fileptr,sion_fileptr->flags,rc));
222 if (NULL == sion_fileptr)
return SION_SIZE_NOT_VALID;
232 #if defined(_SION_SIONFWD)
233 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
234 return _sion_file_write_sionfwd(data,bytes,sion_fileptr->fd,&sion_fileptr->position);
237 #ifdef _SION_IME_NATIVE
238 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
239 return _sion_file_write_ime_native(data, bytes, sion_fileptr->fd);
243 return _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_file_write: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
258 if (NULL == sion_fileptr)
return SION_SIZE_NOT_VALID;
268 #if defined(_SION_SIONFWD)
269 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
270 return _sion_file_read_sionfwd(data,bytes,sion_fileptr->fd,&sion_fileptr->position);
273 #ifdef _SION_IME_NATIVE
274 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
275 return _sion_file_read_ime_native(data, bytes, sion_fileptr->fd);
279 return _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_file_read: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
290 if (NULL == sion_fileptr)
return SION_SIZE_NOT_VALID;
297 #if defined(_SION_SIONFWD)
298 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
299 return _sion_file_get_opt_blksize_sionfwd(sion_fileptr->fd);
302 #ifdef _SION_IME_NATIVE
303 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
304 return _sion_file_get_opt_blksize_ime_native(sion_fileptr->fd);
308 return _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_file_get_opt_blksize: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
337 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
339 return 0 == stat(fname, &sbuf);
341 #error "No platform selected."
344 #if defined(_SION_SIONFWD)
345 else if(apiflag & SION_FILE_FLAG_SIONFWD) {
346 return sionfwd_stat_file(fname);
349 #ifdef _SION_IME_NATIVE
350 else if (apiflag & SION_FILE_FLAG_IME_NATIVE) {
352 return 0 == ime_native_stat(fname, &sbuf);
356 return _sion_errorprint(0,_SION_ERROR_RETURN,
"_sion_file_stat_file2: cannot find valid api flag (flags=%d)\n",apiflag);
368 if (NULL == sion_fileptr)
return SION_SIZE_NOT_VALID;
379 #if defined(_SION_SIONFWD)
380 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
381 sion_fileptr->position = startpointer;
382 return sion_fileptr->position;
385 #ifdef _SION_IME_NATIVE
386 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
387 return _sion_file_set_position_ime_native(sion_fileptr->fd, startpointer);
391 return _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_file_set_position: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
402 if (NULL == sion_fileptr)
return SION_SIZE_NOT_VALID;
413 #if defined(_SION_SIONFWD)
414 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
415 return sion_fileptr->position;
418 #ifdef _SION_IME_NATIVE
419 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
420 return _sion_file_get_position_ime_native(sion_fileptr->fd);
424 return _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_file_get_position: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
435 if (NULL == sion_fileptr)
return SION_NOT_SUCCESS;
446 #if defined(_SION_SIONFWD)
447 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
448 return _sion_file_flush_sionfwd(sion_fileptr->fd);
451 #ifdef _SION_IME_NATIVE
452 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
453 return _sion_file_flush_ime_native(sion_fileptr->fd);
457 return _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_file_flush: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
468 if( sion_fileptr == NULL )
return SION_NOT_SUCCESS;
478 #if defined(_SION_SIONFWD)
479 }
else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
480 return _sion_file_purge_sionfwd(sion_fileptr->fd);
483 return _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_file_purge: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
496 if( sion_fileptr == NULL )
return SION_NOT_SUCCESS;
507 #if defined(_SION_SIONFWD)
508 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
509 return _sion_file_set_buffer_sionfwd(sion_fileptr->fd, buffer, buffer_size);
512 #ifdef _SION_IME_NATIVE
513 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
514 return _sion_file_set_buffer_ime_native(sion_fileptr->fd, buffer, buffer_size);
518 return _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_file_set_buffer: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
530 if( sion_fileptr == NULL )
return SION_NOT_SUCCESS;
534 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"internal error: second fileptr already set, aborting ...\n"));
537 sion_fileptr->second_fileptr=fileptr;
541 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"internal error: second fileptr could not be set for non-ANSI file, aborting ...\n"));
552 if( sion_fileptr == NULL )
return SION_NOT_SUCCESS;
557 sion_fileptr->second_fileptr=NULL;
560 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"internal error: second fileptr was not set, aborting ...\n"));
563 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"internal error: second fileptr could not be unset for non-ANSI file, aborting ...\n"));
574 if( sion_fileptr == NULL )
return SION_ID_UNDEF;
577 return sion_fileptr->fd;
580 return fileno(sion_fileptr->second_fileptr);
582 return fileno(sion_fileptr->fileptr);
585 #if defined(_SION_SIONFWD)
586 else if(sion_fileptr->flags & SION_FILE_FLAG_SIONFWD) {
587 return SION_ID_UNDEF;
590 #ifdef _SION_IME_NATIVE
591 else if (sion_fileptr->flags & SION_FILE_FLAG_IME_NATIVE) {
592 return sion_fileptr->fd;
596 return _sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"_sion_file_get_fd: cannot find valid file flag (flags=%d)\n",sion_fileptr->flags);
612 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
613 return fopen(fname,
"w");
614 #elif defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
615 int fd = open64(fname, O_CREAT | O_RDWR, 0664);
616 return fdopen(fd,
"w");
618 #error "No platform selected."
631 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
633 return fopen(fname,
"r+");
634 #elif defined(_SION_AIX)
635 int fd = open64(fname, O_CREAT | O_RDWR, 0664);
636 return fdopen(fd,
"r+");
637 #elif defined(_SION_BGP) || defined(_SION_BGQ)
638 int fd = open64(fname, O_RDWR, 0664);
639 return fdopen(fd,
"r+");
641 #error "No platform selected."
654 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
655 return fopen(fname,
"r");
656 #elif defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
657 int fd = open64(fname, O_RDONLY, 0664);
658 return fdopen(fd,
"r");
660 #error "No platform selected."
672 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
673 return (0 == fclose(fileptr)) ? SION_SUCCESS : SION_NOT_SUCCESS;
675 #error "No platform selected."
676 return SION_NOT_SUCCESS;
687 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
688 int fd = fileno(fileptr);
690 if (fstat(fd, &sbuf) == 0) {
691 return sbuf.st_blksize;
693 return SION_SIZE_NOT_VALID;
696 #error "No platform selected."
697 return SION_SIZE_NOT_VALID;
711 DPRINTFP((32,
"_sion_set_position_ansi", -1,
"enter (to %lld) (to %ld)\n", (
long long) startpointer, (
long) startpointer));
713 #if defined(_SION_LINUX) || defined(_SION_BGP) || defined(_SION_BGQ)
714 off_t offset = (off_t) startpointer;
715 if (offset != startpointer) {
716 DPRINTFP((32,
"_sion_set_position_ansi", -1,
"_sion_set_position_ansi: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
717 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
718 return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_set_position_ansi: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
719 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
721 int fd = fileno(fileptr);
723 newpos = result = lseek(fd, offset, SEEK_SET);
724 #if defined(_SION_LINUX)
725 DPRINTFP((1024,
"_sion_set_position_ansi", -1,
"set position=%lld (LINUX)\n", (
long long) result));
727 #elif defined(_SION_DARWIN)
728 long offset = (long) startpointer;
729 if (offset != startpointer) {
730 DPRINTFP((32,
"_sion_set_position_ansi", -1,
"_sion_set_position_ansi: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
731 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
732 return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_set_position_ansi: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
733 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
736 newpos = result = fseek(fileptr, offset, SEEK_SET);
737 DPRINTFP((1024,
"_sion_set_position_ansi", -1,
"set position=%lld (LINUX)\n", (
long long) result));
738 #elif defined(_SION_AIX)
739 off64_t offset = (off_t) startpointer;
741 if (offset != startpointer) {
742 return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_set_position_ansi: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
743 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
745 result = fseeko64(fileptr, offset, SEEK_SET);
746 newpos = result = ftello64(fileptr);
748 #error "No platform selected."
749 newpos = SION_SIZE_NOT_VALID;
751 DPRINTFP((32,
"_sion_set_position_ansi", -1,
"leave (%lld --> %lld)\n",(
long long) startpointer, (
long long) newpos));
765 #if defined(_SION_LINUX)
767 int fd = fileno(fileptr);
768 resulto = lseek(fd,0,SEEK_CUR);
769 result = (sion_int64) resulto;
770 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (LINUX)\n", (
long) result));
771 #elif defined(_SION_DARWIN)
773 resulto = ftello(fileptr);
774 result = (sion_int64) resulto;
775 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (DARWIN)\n", (
long) result));
776 #elif defined(_SION_AIX)
777 result = ftell(fileptr);
778 DPRINTFP((4096,
"_sion_get_position", -1,
"got position=%lld (AIX)\n", result));
779 #elif defined(_SION_BGP)
781 int fd = fileno(fileptr);
782 resulto = lseek(fd, 0, SEEK_CUR);
783 result = (sion_int64) resulto;
784 DPRINTFP((4096,
"_sion_get_position", -1,
"got position=%lld (BGP)\n", result));
785 #elif defined(_SION_BGQ)
787 int fd = fileno(fileptr);
788 resulto = lseek(fd, 0, SEEK_CUR);
789 result = (sion_int64) resulto;
790 DPRINTFP((4096,
"_sion_get_position", -1,
"got position=%lld (BGQ)\n", result));
792 #error "No platform selected."
793 result = SION_SIZE_NOT_VALID;
806 return (0 == fflush(fileptr)) ? SION_SUCCESS : SION_NOT_SUCCESS;
828 DPRINTFP((32,
"_sion_file_set_buffer", -1,
"set buffer of fileptr\n"));
829 return (0 == setvbuf(fileptr, buffer, _IOFBF, (
size_t) buffer_size)) ? SION_SUCCESS : SION_NOT_SUCCESS;
841 return (bytes == fwrite(data, 1, bytes, fileptr)) ? bytes : -1;
855 if (fread(data, 1, bytes, fileptr) < bytes) {
876 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
878 fd = open(fname, O_CREAT | O_RDWR, 0664);
879 }
while (-1 == fd && EINTR == errno);
880 #elif defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
882 fd = open64(fname, O_CREAT | O_RDWR, 0664);
883 }
while (-1 == fd && EINTR == errno);
885 #error "No platform selected."
902 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
904 fd = open(fname, O_RDWR, 0664);
905 }
while (-1 == fd && EINTR == errno);
906 #elif defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
908 fd = open64(fname, O_RDWR, 0664);
909 }
while (-1 == fd && EINTR == errno);
911 #error "No platform selected."
928 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
930 fd = open(fname, O_RDONLY, 0664);
931 }
while (-1 == fd && EINTR == errno);
932 #elif defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
934 fd = open64(fname, O_RDONLY, 0664);
935 }
while (-1 == fd && EINTR == errno);
937 #error "No platform selected."
951 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
952 return (0 == close(fd)) ? SION_SUCCESS : SION_NOT_SUCCESS;
954 #error "No platform selected."
955 return SION_NOT_SUCCESS;
966 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_AIX) || defined(_SION_BGP) || defined(_SION_BGQ)
968 if (fstat(fd, &sbuf) == 0) {
969 return sbuf.st_blksize;
971 return SION_SIZE_NOT_VALID;
974 #error "No platform selected."
975 return SION_SIZE_NOT_VALID;
987 sion_int64 newpos = SION_SIZE_NOT_VALID;
989 DPRINTFP((32,
"_sion_set_position_posix", -1,
"enter (to %lld)\n", (
long long) startpointer));
991 #if defined(_SION_LINUX) || defined(_SION_DARWIN) || defined(_SION_BGP) || defined(_SION_BGQ)
992 off_t offset = (off_t) startpointer;
993 if (offset != startpointer) {
994 return (_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_set_position_posix: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
995 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
998 newpos = result = lseek(fd, offset, SEEK_SET);
999 #if defined(_SION_LINUX) || defined(_SION_DARWIN)
1000 DPRINTFP((4096,
"_sion_set_position_posix", -1,
"set position=%lld (LINUX)\n", (
long long) result));
1002 #elif defined(_SION_AIX)
1003 off64_t offset = (off_t) startpointer;
1005 if (offset != startpointer) {
1006 return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,
"_sion_set_position_posix: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n",
1007 offset,
sizeof(offset), startpointer,
sizeof(startpointer)));
1009 newpos = result = lseek(fd, offset, SEEK_SET);
1011 #error "No platform selected."
1012 newpos = SION_SIZE_NOT_VALID;
1014 DPRINTFP((32,
"_sion_set_position_posix", -1,
"leave (to %lld)\n",(
long long) startpointer));
1026 sion_int64 result=SION_SIZE_NOT_VALID;
1029 resulto = lseek(fd,0,SEEK_CUR);
1030 result = (sion_int64) resulto;
1032 #if defined(_SION_LINUX)
1033 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (LINUX)\n", (
long) result));
1034 #elif defined(_SION_DARWIN)
1035 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (DARWIN)\n", (
long) result));
1036 #elif defined(_SION_AIX)
1037 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (AIX)\n", (
long) result));
1038 #elif defined(_SION_BGP)
1039 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (BGP)\n", (
long) result));
1040 #elif defined(_SION_BGQ)
1041 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (BGQ)\n", (
long) result));
1056 #if defined(_SION_BGQ)
1062 }
while (frc != 0 && EINTR == errno);
1065 return (0 == frc) ? SION_SUCCESS : SION_NOT_SUCCESS;
1079 #if defined(_SION_BGQ)
1085 }
while (frc != 0 && EINTR == errno);
1088 return (0 == frc) ? SION_SUCCESS : SION_NOT_SUCCESS;
1100 DPRINTFP((32,
"_sion_file_set_buffer", -1,
"set buffer of fileptr\n"));
1101 return SION_SUCCESS;
1115 k = write(fd, data, bytes);
1117 if (errno != EINTR) {
1121 }
else if (k == bytes) {
1130 data = (
char*)data + k;
1148 k = read(fd, data, bytes);
1150 if (errno != EINTR) {
1154 }
else if (k == 0) {
1157 }
else if (k == bytes) {
1166 data = (
char*)data + k;
1171 #if defined(_SION_SIONFWD)
1179 int _sion_file_open_sionfwd_write_create(
const char *fname,
unsigned int addflags) {
1180 return sionfwd_open(fname, SIONFWD_WRITE | SIONFWD_CREATE);
1190 int _sion_file_open_sionfwd_write_existing(
const char *fname,
unsigned int addflags) {
1191 return sionfwd_open(fname, SIONFWD_WRITE);
1201 int _sion_file_open_sionfwd_read(
const char *fname,
unsigned int addflags) {
1202 return sionfwd_open(fname, SIONFWD_READ);
1211 int _sion_file_close_sionfwd(
int fd) {
1212 return (0 == sionfwd_close(fd)) ? SION_SUCCESS : SION_NOT_SUCCESS;
1221 long _sion_file_get_opt_blksize_sionfwd(
int fd) {
1222 return sionfwd_stat_blksize(fd);
1231 int _sion_file_flush_sionfwd(
int fd) {
1232 return (sionfwd_flush(fd) == 0) ? SION_SUCCESS : SION_NOT_SUCCESS;
1243 int _sion_file_purge_sionfwd(
int fd) {
1244 return (sionfwd_flush(fd) == 0) ? SION_SUCCESS : SION_NOT_SUCCESS;
1255 int _sion_file_set_buffer_sionfwd(
int fd,
char *buffer, sion_int32 buffer_size) {
1256 DPRINTFP((32,
"_sion_file_set_buffer", -1,
"set buffer of fileptr\n"));
1257 return SION_SUCCESS;
1269 sion_int64 _sion_file_write_sionfwd(
const void *data, sion_int64 bytes,
int fd, sion_int64 *position) {
1270 sion_int64 written = sionfwd_pwrite(fd, data, bytes, *position);
1271 if (written != -1) { *position += written; }
1286 sion_int64 _sion_file_read_sionfwd(
void *data, sion_int64 bytes,
int fd, sion_int64 *position) {
1287 sion_int64 bread = sionfwd_pread(fd, data, bytes, *position);
1288 if (bread != -1) { *position += bread; }
1297 #ifdef _SION_IME_NATIVE
1305 int _sion_file_open_ime_native_write_create(
const char *fname,
unsigned int addflags)
1310 fd = ime_native_open(fname, O_CREAT | O_RDWR, 0664);
1311 }
while (-1 == fd && EINTR == errno);
1323 int _sion_file_open_ime_native_write_existing(
const char *fname,
unsigned int addflags)
1328 fd = ime_native_open(fname, O_RDWR, 0664);
1329 }
while (-1 == fd && EINTR == errno);
1341 int _sion_file_open_ime_native_read(
const char *fname,
unsigned int addflags)
1346 fd = ime_native_open(fname, O_RDONLY, 0664);
1347 }
while (-1 == fd && EINTR == errno);
1358 int _sion_file_close_ime_native(
int fd)
1360 return (0 == ime_native_close(fd)) ? SION_SUCCESS : SION_NOT_SUCCESS;
1369 long _sion_file_get_opt_blksize_ime_native(
int fd)
1371 return SION_SIZE_NOT_VALID;
1381 sion_int64 _sion_file_set_position_ime_native(
int fd, sion_int64 startpointer)
1383 sion_int64 newpos = SION_SIZE_NOT_VALID;
1385 DPRINTFP((32,
"_sion_set_position_ime_native", -1,
"enter (to %lld)\n", (
long long)startpointer));
1387 off_t offset = (off_t)startpointer;
1388 if (offset != startpointer) {
1389 return _sion_errorprint(SION_SIZE_NOT_VALID, _SION_ERROR_RETURN,
1390 "_sion_set_position_ime_native: cannot set position to %ld (%zu),%lld (%zu) offset conversion error\n", offset,
sizeof(offset),
1391 startpointer,
sizeof(startpointer));
1394 newpos = result = ime_native_lseek(fd, offset, SEEK_SET);
1396 DPRINTFP((32,
"_sion_set_position_ime_native", -1,
"leave (to %lld)\n", (
long long)startpointer));
1407 sion_int64 _sion_file_get_position_ime_native(
int fd)
1409 sion_int64 result = SION_SIZE_NOT_VALID;
1412 resulto = ime_native_lseek(fd, 0, SEEK_CUR);
1413 result = (sion_int64)resulto;
1415 DPRINTFP((4096,
"_sion_get_position", -1,
"get position=%ld (LINUX)\n", (
long)result));
1426 int _sion_file_flush_ime_native(
int fd)
1431 frc = ime_native_fsync(fd);
1432 }
while (frc != 0 && EINTR == errno);
1434 return (0 == frc) ? SION_SUCCESS : SION_NOT_SUCCESS;
1445 int _sion_file_set_buffer_ime_native(
int fd,
char *buffer, int32_t buffer_size)
1448 DPRINTFP((32,
"_sion_file_set_buffer", -1,
"set buffer of fileptr\n"));
1449 return SION_SUCCESS;
1460 sion_int64 _sion_file_write_ime_native(
const void *data, sion_int64 bytes,
int fd)
1464 k = ime_native_write(fd, data, bytes);
1466 if (errno != EINTR) {
1470 }
else if (k == bytes) {
1479 data = (
char *)data + k;
1494 sion_int64 _sion_file_read_ime_native(
void *data, sion_int64 bytes,
int fd)
1498 k = ime_native_read(fd, data, bytes);
1500 if (errno != EINTR) {
1504 }
else if (k == 0) {
1507 }
else if (k == bytes) {
1516 data = (
char *)data + k;
1530 if (sion_fileptr == NULL) {
1531 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"cannot allocate _sion_fileptr structure of size %lu (_sion_fileptr), aborting ...\n",
1535 sion_fileptr->fileptr = NULL;
1536 sion_fileptr->second_fileptr = NULL;
1537 sion_fileptr->fd = -1;
1538 sion_fileptr->flags = 0;
1539 #if defined(_SION_SIONFWD)
1540 sion_fileptr->position = 0;
1543 return (sion_fileptr);
1546 #define STR_PRT(X) case X: return # X
1558 #if defined(_SION_SIONFWD)
1559 STR_PRT(SION_FILE_FLAG_SIONFWD);
1570 if(!sion_fileptr)
return(
"<undefined>");
1571 flags = sion_fileptr->flags;
1576 return(
"<ANSI,WRITE,CREATE>");
1578 return(
"<ANSI,WRITE>");
1581 return(
"<ANSI,READ>");
1586 return(
"<POSIX,WRITE,CREATE>");
1588 return(
"<POSIX,WRITE>");
1591 return(
"<POSIX,READ>");
1594 #if defined(_SION_SIONFWD)
1595 else if (flags & SION_FILE_FLAG_SIONFWD) {
1598 return(
"<SIONFWD,WRITE,CREATE>");
1600 return(
"<SIONFWD,WRITE>");
1603 return(
"<SIONFWD,READ>");
1607 #ifdef _SION_IME_NATIVE
1608 else if (flags & SION_FILE_FLAG_IME_NATIVE) {
1611 return "<IME_NATIVE,WRITE,CREATE>";
1613 return "<IME_NATIVE,WRITE>";
1616 return "<IME_NATIVE,READ>";
1620 return(
"<unknown>");
int _sion_file_stat_file2(const char *fname, unsigned int apiflag)
Check if file exists with appropriate low-level API.
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
int _sion_file_unset_second_fileptr(_sion_fileptr *sion_fileptr)
Unset second fileptr for file if opened with ANSI.
sion_int64 _sion_file_read_posix(void *data, sion_int64 bytes, int fd)
POSIX: Read data from file.
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
long _sion_file_get_opt_blksize_posix(int fd)
POSIX: Get optional file system block size for a file.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
int _sion_file_close_posix(int fd)
POSIX: Close a file.
int _sion_file_open_posix_write_existing(const char *fname, unsigned int addflags)
POSIX: Open a new file for writing.
sion_int64 _sion_file_get_position_posix(int fd)
POSIX: Get the current position in file.
int _sion_file_set_buffer_posix(int fd, char *buffer, sion_int32 buffer_size)
POSIX: set buffer of fd.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
int _sion_file_set_buffer(_sion_fileptr *sion_fileptr, char *buffer, sion_int32 buffer_size)
Set buffer of fp.
int _sion_file_get_fd(_sion_fileptr *sion_fileptr)
Utility function: Get POSIX fp.
char * _sion_get_fileptr_desc(_sion_fileptr *sion_fileptr)
int _sion_file_open_posix_write_create(const char *fname, unsigned int addflags)
POSIX: Create and open a new file for writing.
FILE * _sion_file_open_ansi_read(const char *fname, unsigned int addflags)
ANSI: Open a file for reading.
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
sion_int64 _sion_file_get_position_ansi(FILE *fileptr)
ANSI: Get the current position in file.
_sion_fileptr * _sion_file_alloc_and_init_sion_fileptr(void)
Create and return _sion_fileptr.
char * _sion_fileptrflags_to_str(unsigned int flag)
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
int _sion_file_close_ansi(FILE *fileptr)
ANSI: Close a file.
int _sion_file_set_buffer_ansi(FILE *fileptr, char *buffer, sion_int32 buffer_size)
ANSI: set buffer of fp.
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
int _sion_file_stat_file(const char *fname)
Check if file exists (LARGE_FILE support on BlueGene)
sion_int64 _sion_file_write_posix(const void *data, sion_int64 bytes, int fd)
POSIX: Write data to file.
int _sion_file_open_posix_read(const char *fname, unsigned int addflags)
POSIX: Open a file for reading.
sion_int64 _sion_file_set_position_posix(int fd, sion_int64 startpointer)
POSIX: Set the start position for the current task.
sion_int64 _sion_file_read_ansi(void *data, sion_int64 bytes, FILE *fileptr)
ANSI: Read data from file.
FILE * _sion_file_open_ansi_write_existing(const char *fname, unsigned int addflags)
ANSI: Open a new file for writing.
int _sion_file_flush_ansi(FILE *fileptr)
ANSI: Flush the data to the disk.
int _sion_file_purge_ansi(FILE *fileptr)
ANSI: Purge the data to the disk.
int _sion_file_purge_posix(int fd)
POSIX: Purge the data to the disk.
long _sion_file_get_opt_blksize_ansi(FILE *fileptr)
ANSI: Get optional file system block size for a file.
sion_int64 _sion_file_set_position_ansi(FILE *fileptr, sion_int64 startpointer)
ANSI: Set the start position for the current task.
int _sion_file_flush_posix(int fd)
POSIX: Flush the data to the disk.
sion_int64 _sion_file_write_ansi(const void *data, sion_int64 bytes, FILE *fileptr)
ANSI: Write data to file.
FILE * _sion_file_open_ansi_write_create(const char *fname, unsigned int addflags)
ANSI: Create and open a new file for writing.
int _sion_file_set_second_fileptr(_sion_fileptr *sion_fileptr, FILE *fileptr)
Set second fileptr for file if opened with ANSI.
#define SION_FILE_FLAG_READ
#define SION_FILE_FLAG_CREATE
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_WRITE
#define SION_FILE_FLAG_SCNDANSI
#define SION_FILE_FLAG_POSIX