I have some code that uses the low level i/o read
and write
system calls, as described on page 170 of the C programming language book Kernighan and Ritchie.
The function prototypes are this
int n_read = read ( int fd, char *buf, int n )
int n_read = write ( int fd, char *buf, int n )
now the two .c file that uses these read
and write
are called by a larger fortran based program to read and write lots of data.
the C code is simply this, with no #include
of any kind, having the underscore after the function name and passing by reference:
int read_ ( int *descriptor, char *buffer, int *nbyte )
{
return ( read( *descriptor, buffer, *nbyte ) );
}
int write_ ( int *descriptor, char *buffer, int *nbyte )
{
return ( write( *descriptor, buffer, *nbyte ) );
}
and the larger fortran based program will do something like this
INTEGER nbyte
COMPLEX*16 matrix(*)
INTEGER READ, WRITE
EXTERNAL READ, WRITE
status = READ( fd, matrix, nbyte )
if ( status .eq. -1 ) then
CALL ERROR('C call read failure')
stop
endif
As you may have already guessed, this works fine for nbyte values less than 2^31. I have a need to read more than 2 GB of data, so i need nbyte to be a long integer and INTEGER*8 in fortran.
Is there an equivalent read64 and write64, like there is an lseek64 provided by unistd.h and features.h ?
what is the best way to recode this?
should i use fread and fwrite ?
is the int fd
from the low level write
the same as FILE *stream
from fread()
?
my requirement is being able to pass a long integer of 8 bytes to allow for values up to 100 to 500 gigabytes or an integer having 12 digits, which is all for the value of nbyte
Am i gaining anything or losing out by currently using read
and write
which is identified as a "system call" ? What does this mean?
read()
function, you would have found the declaration that Leandros gave you and probably solved your problem yourself.man
command. For example,man 2 read
tells you all about theread
function. The number 2 indicates the section in the manual. Section 1 is mostly shell commands. Sections 2 and 3 have the C library functions.