- res = _lseek (fd, (ALOCK_SLOT_SIZE * slot), SEEK_SET);
- if (res == -1) return -1;
- res = _locking( fd, _LK_UNLCK, ALOCK_SLOT_SIZE );
+ HANDLE hh = _get_osfhandle ( fd );
+ if ( !UnlockFile ( hh, ALOCK_SLOT_SIZE*slot, 0,
+ ALOCK_SLOT_SIZE, 0 ))
+ return -1;
+#else
+# error alock needs lockf, fcntl, or LockFile[Ex]
+#endif
+
+ return 0;
+}
+
+static int
+alock_share_lock ( int fd, int slot )
+{
+ int res;
+
+#if defined( HAVE_LOCKF )
+ res = 0; /* lockf has no shared locks */
+#elif defined ( HAVE_FCNTL )
+ struct flock lock_info;
+ (void) memset ((void *) &lock_info, 0, sizeof (struct flock));
+
+ /* The shared lock replaces the existing lock */
+ lock_info.l_type = F_RDLCK;
+ lock_info.l_whence = SEEK_SET;
+ lock_info.l_start = (off_t) (ALOCK_SLOT_SIZE * slot);
+ lock_info.l_len = (off_t) ALOCK_SLOT_SIZE;
+
+ res = fcntl (fd, F_SETLK, &lock_info);