A question about reading from a UART

Hi All
Iam using devc-8250ser drivers for the UART ST16C654CJ68

i have the following code to read from the UART

int ReadUart(char *uartPath, unsigned char *buf, int size, int option)
int fd, len = 0;

 /* Open a file for input & output */
 // fd = open( uartPath, O_RDWR );
fd = open(uartPath, O_RDWR, S_IRWXU ); 
if (fd == -1) {
        printf("ERROR: uutifReadUart, Device %s can't be Opened.\r\n", uartPath);
        return (-1);
	len = read(fd, buf, size);
} else {
    /* Flush the UART */
    while(len) {
              len = read(fd, buf, UUTIF_UART_DATA_SIZE);


/* Close the file */
close( fd );

 return len;


my boss is telling me that this is no good , and reading should be only when there is data avaiable , I dont know what he means , I am assuming that I have to wait for an intrrupt or a reg value to Read Am I right?

and if somebody have idea how can I make this function read only when there is data , that would help a lot

Thanks All

This code is good, it depends on what you want to acheive and in the context from which it is called.

If I were to guess what you need, I suggest you use io_notify or select() ask the driver to send you notification when there is data in the input buffer. I would also open the device in async mode so that when you do a read you don’t block in case there is less data available then what you are asking for.