N
Noel Mosa
Hi,
i have a file in memory in a char* string(which i read using buffered
ifstreams from c++) and want to write a fake read() function for a C
program that usually reads from files.
What id like to know is the following:
how can i best copy the array to the buffer?
can i for example just say:
static int myindex;
int myRead(char* mysource ,char* buf, int size){
return strncpy(buf[myindex], mysource, size);
}
id'like myRead to behabe exactly as read(). inclusive return values and
beaviour at end of file. which lead us to my second important question:
how do i handle when the last sector is copied?
lets say i only have 3 bytes left (starting from the index) and the
program requests 10.
does strncpy terminates the string for me or do i have to take care of
generating an eof?
thanks for all answers!
also a pointer to a good read() reference is welcome!
i have a file in memory in a char* string(which i read using buffered
ifstreams from c++) and want to write a fake read() function for a C
program that usually reads from files.
What id like to know is the following:
how can i best copy the array to the buffer?
can i for example just say:
static int myindex;
int myRead(char* mysource ,char* buf, int size){
return strncpy(buf[myindex], mysource, size);
}
id'like myRead to behabe exactly as read(). inclusive return values and
beaviour at end of file. which lead us to my second important question:
how do i handle when the last sector is copied?
lets say i only have 3 bytes left (starting from the index) and the
program requests 10.
does strncpy terminates the string for me or do i have to take care of
generating an eof?
thanks for all answers!
also a pointer to a good read() reference is welcome!