
Description | Cautions | Example | Errors | See Also
Name: |
int dx_fileread(handle, buffer, count) | |
Inputs: |
int handle |
|
void *buffer |
| |
unsigned int count |
| |
Returns: |
number of bytes if success | |
-1 if failure | ||
Category: |
File Management | |
The dx_fileread( ) function reads data from a file associated with the file handle. The function will read the number of bytes from the file associated with the handle into the buffer. The number of bytes read may be less than the value of count if there are fewer than count bytes left in the file or if the file was opened in text mode. See the _read function in the Microsoft Visual C++ Run-Time Library Reference for more information.
Use dx_fileread( ) instead of _read to ensure the compatibility of applications with the libraries across various versions of Visual C++.
#include <stdio.h>
#include <srllib.h>
#include <dxxxlib.h>
#include <windows.h>
int cd; /* channel descriptor */
DX_UIO myio; /* user definable I/O structure */
/*
* User defined I/O functions
*/
int my_read(fd,ptr,cnt)
int fd;
char * ptr;
unsigned cnt;
{
printf("My read\n");
return(dx_fileread(fd,ptr,cnt));
}
/*
* my write function
*/
int my_write(fd,ptr,cnt)
int fd;
char * ptr;
unsigned cnt;
{
printf("My write \n");
return(dx_filewrite(fd,ptr,cnt));
}
/*
* my seek function
*/
long my_seek(fd,offset,whence)
int fd;
long offset;
int whence;
{
printf("My seek\n");
return(dx_fileseek(fd,offset,whence));
}
void main(argc,argv)
int argc;
char *argv[];
{
.
. /* Other initialization */
.
DX_UIO uioblk;
/* Initialize the UIO structure */
uioblk.u_read=my_read;
uioblk.u_write=my_write;
uioblk.u_seek=my_seek;
/* Install my I/O routines */
dx_setuio(uioblk);
vodat_fd = dx_fileopen("JUNK.VOX",O_RDWR|O_BINARY);
/*This block uses standard I/O functions */
iott->io_type = IO_DEV|IO_CONT
iott->io_fhandle = vodat_fd;
iott->io_offset = 0;
iott->io_length = 20000;
/*This block uses my I/O functions */
iottp++;
iottp->io_type = IO_DEV|IO_UIO|IO_CONT
iottp->io_fhandle = vodat_fd;
iott->io_offset = 20001;
iott->io_length = 20000;
/*This block uses standard I/O functions */
iottp++
iott->io_type = IO_DEV|IO_CONT
iott->io_fhandle = vodat_fd;
iott->io_offset = 20002;
iott->io_length = 20000;
/*This block uses my I/O functions */
iott->io_type = IO_DEV|IO_UIO|IO_EOT
iott->io_fhandle = vodat_fd;
iott->io_offset = 10003;
iott->io_length = 20000;
devhandle = dx_open("dxxxB1C1", 0);
dx_sethook(devhandle, DX-ONHOOK,EV_SYNC)
dx_wtring(devhandle,1,DX_OFFHOOK,EV_SYNC);
dx_clrdigbuf;
if(dx_rec(devhandle,iott,(DX_TPT*)NULL,RM_TONE|EV_SYNC) == -1) {
perror("");
exit(1);
}
dx_clrdigbuf(devhandle);
if(dx_play(devhandle,iott,(DX_TPT*)EV_SYNC) == -1 {
perror("");
exit(1);
}
dx_close(devhandle);
If this function returns -1 to indicate failure, a system error has occurred; use dx_fileerrno( ) to obtain the system error value. Refer to the dx_fileerrno( ) function for a list of the possible system error values.
Click here to contact Dialogic Customer Engineering
Copyright 2002, Dialogic Corporation