As far as I understand the only way to get the UART buffer data count, is, as you mentioned, using the ioctl function. I didn't quite understand your question, are you having issues using iotctl?
If so, I'll post here some links that I believe you might find helpful:
I used ioctl(fd,FIONREAD,&counter), I include <termios.h> , but it have error :
root@edison:~/eulerspace# gcc main2.c -o main2 -lmraa
main2.c: In function 'main':
main2.c:33:23: error: 'FIONREAD' undeclared (first use in this function)
ioctl(serialPort, FIONREAD, &counter);
my Guess is you are not including the necessary header files. My guess is that it is in:
I can receive data in the buffer ,thanks a lot.