Source code for serial port

Hi,

I am working with sun Solaris 5.9 and in my application,I have to communicate with Serial port(i.e /dev/term/a).
So I need source code to by which I can do the following things--
1)check the port is available or not.If it dosn't find the port,it should throw the error message(i.e. port not found!!)
2)If it finds then it should check wether any device is connected or not.

please help me on this.you can tell me code on C/C++.

Thanks in advance...