int f_lockwrite(char* szMsg, int iFileDesc)
{
struct flock *stFlock;
int n;
stFlock = (struct flock*)malloc(sizeof(struct flock));
stFlock->l_type = F_WRLCK;
fcntl(iFileDesc, F_SETLKW, stFlock);
if ((n = write(iFileDesc, szMsg, 1)) <= 0)
{
return -1;
}
stFlock.l_type = F_UNLCK;
fcntl(iFileDesc, F_SETLK, stFlock);
free(stFlock);
return 1;
}