include wmdesktop.h in misc.h
[nedit-bw.git] / keep_state_for_bck_file.patch
blobef4ff3bdca1e31cdfab6a36ce109010c1ec13f94
1 Subject: keep the file times for backup files
3 ---
5 source/file.c | 18 ++++++++++++++++--
6 1 file changed, 16 insertions(+), 2 deletions(-)
8 diff --quilt old/source/file.c new/source/file.c
9 --- old/source/file.c
10 +++ new/source/file.c
11 @@ -69,6 +69,7 @@ static const char CVSID[] = "$Id: file.c
12 #endif
13 #include <fcntl.h>
14 #endif /*VMS*/
15 +#include <utime.h>
17 #include <Xm/Xm.h>
18 #include <Xm/ToggleB.h>
19 @@ -1394,6 +1395,7 @@ static int writeBckVersion(WindowInfo *w
20 struct stat statbuf;
21 int in_fd, out_fd;
22 char *io_buffer;
23 + struct utimbuf utimbuf;
24 #define IO_BUFFER_SIZE ((size_t)(1024*1024))
26 /* Do only if version backups are turned on */
27 @@ -1423,8 +1425,8 @@ static int writeBckVersion(WindowInfo *w
30 /* Get permissions of the file.
31 - We preserve the normal permissions but not ownership, extended
32 - attributes, et cetera. */
33 + We preserve the normal permissions but not extended attributes,
34 + et cetera. */
35 if (fstat(in_fd, &statbuf) != 0) {
36 return FALSE;
38 @@ -1443,6 +1445,14 @@ static int writeBckVersion(WindowInfo *w
39 return bckError(window, "fchmod() failed", bckname);
42 + /* Set ownership on new file */
43 + if (fchown(out_fd, statbuf.st_uid, statbuf.st_gid) != 0) {
44 + close(in_fd);
45 + close(out_fd);
46 + remove(bckname);
47 + return bckError(window, "fchown() failed", bckname);
48 + }
50 /* Allocate I/O buffer */
51 io_buffer = (char*) malloc(IO_BUFFER_SIZE);
52 if (NULL == io_buffer) {
53 @@ -1495,6 +1505,10 @@ static int writeBckVersion(WindowInfo *w
55 close(out_fd);
57 + utimbuf.actime = statbuf.st_atime;
58 + utimbuf.modtime = statbuf.st_mtime;
59 + utime(bckname, &utimbuf);
61 #endif /* VMS */
63 return FALSE;