Exclusive control between HULFT and user jobs

If you need to control files exclusively between the HULFT services when developing a business application, the method below can be used for this purpose.

In HULFT, when you specify to clear or delete the Send file, the lockf() function (refer to the manual for the operating system for details) is used as the lock method for the Send file and the Receive file.

If the exclusive control for the Send file and Receive file is to be carried out by the business application, use the lockf() function.

<Example of program to carry out the exclusive control>

#include    <stdio.h>
#include    <unistd.h>
#include    <sys/types.h>
#include    <sys/fcntl.h>
#include    <errno.h>

main() 
{ 
   int   wfp, ans, i; 
   char  buf[5]; 

   wfp = open( "./rcvfile.dat", O_RDWR|O_CREAT, 0666 ); 
   if( wfp == -1 ){ 
         perror( "OPEN" ); 
         exit( 1 ); 
   } 
   lockf( wfp, F_LOCK, 0 ); 
   ans = read( wfp, buf, sizeof( buf ) ); 
   if( ans < 0 ){ 
         perror( "READ" ); 
         close( wfp ); 
         exit( 1 ); 
   } 
   printf( "read:[%s]\n", buf ); 
   close( wfp ); 
   exit( 0 ); 
}