Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>unlock() release file-sharing locks</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 unlock()                Release File-Sharing Locks

 #include   <io.h>

 int        unlock(handle,offset,length);
 int        handle;                      Handle associated with file
 long       offset;                      Address of area to be unlocked
 long       length;                      Length of area to be unlocked

    unlock() unlocks 'length' bytes of the file associated with 'handle',
    starting at the position 'offset'.  Unlocking a file permits other
    processes to read or write to previously locked bytes.  A file should
    not be closed before all locks are removed.  Likewise, a program must
    release all file locks before it finishes.  'handle', 'offset' and
    'length' should be identical to the values provided for a preceding
    lock().

       Returns:     0, if successful; -1 is returned on error.

   -------------------------------- Example ---------------------------------

    The following statements open a file, lock the first 1000 bytes of
    the file, do some operation on it and then unlock the file.

           #include <stdio.h>      /* for printf */
           #include <io.h>         /* for lock, unlock, _open and close */
           #include <fcntl.h>      /* for constants */

           main()
           {
               int handle;

               if ((handle =
                 _open("\network\shared.dat",O_RDWR|O_DENYNONE)) == -1) {
                    printf("Error opening file.\n");
                    exit(1);
               }
               if (lock(handle,0L,1000L) == -1) {
                   printf("Unable to lock file.\n");
                   exit(1);
               }
                .
                .
                /* do some file operations of first 1000 bytes */
                .
                .
                unlock(handle,0L,1000L);
           close(handle);
           }


See Also: lock() open()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson