Help reading serial port

I am writing a JAVA application that uses two serial ports, one dedicated for TX and the other dedicated for RX. I have the ports enabled and these work fine. I’ve written an native library in C and use it to open the ports, send and receive data. The problem is whilst sending appears to work fine, receive only receives 1 byte before exiting the read loop.

I am aware that I am only trying to read 1 byte at a time, but it should stay in the read loop until either a carriage return is received or there is no space left in the buffer:

http://pastebin.com/4uZu5gVN

Solved…