1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
--- b.c.orig Mon Jul 9 13:22:47 2001
+++ b.c Mon Jul 9 13:22:49 2001
@@ -16,6 +16,9 @@
#include <pwd.h>
#endif
#include <errno.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
@@ -184,6 +187,7 @@
else
b->o = pdefault;
mset(b->marks, 0, sizeof(b->marks));
+ b->filehandle = -1; /* initialize filehande &&& ob */
b->rdonly = 0;
b->orphan = 0;
b->oldcur = 0;
@@ -236,6 +240,10 @@
void brm(B * b)
{
if (b && !--b->count) {
+ if (b->filehandle != -1) {
+ /* close filehandle, free lock &&& ob */
+ close (b->filehandle);
+ }
if (b->changed)
abrerr(b->name);
if (b == errbuf)
@@ -1809,7 +1817,8 @@
B *b;
long skip, amnt;
char *n;
- int nowrite = 0;
+ struct stat sb;
+ int nowrite = 0, fh = -1;
if (!s || !s[0]) {
error = -1;
@@ -1857,6 +1866,12 @@
goto opnerr;
}
+ /* Lock the file &&& ob,petef */
+ if (fi) {
+ fh = dup( fileno(fi) );
+ nowrite = (flock (fh, LOCK_EX | LOCK_NB));
+ }
+
/* Skip data if we need to */
if (skip && lseek(fileno(fi), skip, 0) < 0) {
int r;
@@ -1912,6 +1927,8 @@
vsrm(n);
b->er = error;
+ if (fh != -1)
+ b->filehandle = fh;
return b;
}
|