-
- prev_sb = sb;
-
- mutt_message (_("Waiting for fcntl lock... %d"), ++attempt);
- mutt_sleep (1);
- }
-#endif /* USE_FCNTL */
-
-#ifdef USE_FLOCK
- count = 0;
- attempt = 0;
- while (flock (fd, (excl ? LOCK_EX : LOCK_SH) | LOCK_NB) == -1) {
- struct stat sb;
-
- if (errno != EWOULDBLOCK) {
- mutt_perror ("flock");
- r = -1;
- break;
- }
-
- if (fstat (fd, &sb) != 0)
- sb.st_size = 0;
-
- if (count == 0)
- prev_sb = sb;
-
- /* only unlock file if it is unchanged */
- if (prev_sb.st_size == sb.st_size
- && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
- if (time_out)
- mutt_error _("Timeout exceeded while attempting flock lock!");
-
- r = -1;
- break;
- }
-
- prev_sb = sb;
-
- mutt_message (_("Waiting for flock attempt... %d"), ++attempt);
- mutt_sleep (1);
- }
-#endif /* USE_FLOCK */
-
- if (r == 0 && dot)
- r = dotlock_file(path, time_out);
-
- if (r == -1) {
- /* release any other locks obtained in this routine */
-
-#ifdef USE_FCNTL
- lck.l_type = F_UNLCK;
- fcntl (fd, F_SETLK, &lck);
-#endif /* USE_FCNTL */
-
-#ifdef USE_FLOCK
- flock (fd, LOCK_UN);
-#endif /* USE_FLOCK */
-
- return (-1);