Not able to lock the port

Hi,
I am working with Sun-Solaris 9 and in our application I need to connect the UPS with Serial port,after that I need to monitor it..but before stating communication,It should lock that port,To check it,first i am trying to make sure the lock directory exists and I am able to find it(/var/lock) but not able to lock the port and getting the error message from there---

LOCKDIR=/var/lock in PosixDevLock.c at 53
LOCKDIR=/var/lock in PosixDevLock.c at 57
Error message in PosixDevLock.c at 58
lckStatus value==>2

I am trying to lock the port using the function lock from other file and getting the value in lckStatus variable.

this lock function try to lock the port but during this i am not able to lock the port --

It should not go to the if statement(if (mkdir(LOCKDIR) != 0))but it is and returns the error no.-2 means(no such file or directory )...

Please help me to resolve it...
Thanks in advance