aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2013-03-13 11:42:22 -0700
committerPaul Eggert2013-03-13 11:42:22 -0700
commit47d7532e093db8a5068a40c587915121ffaaad18 (patch)
treea99ea6eca34ea0e9c8d6e8a8d6291833ce27dca5 /lib
parentc7ffccaf17d63cefd34bef0a9becc4e68df3b115 (diff)
downloademacs-47d7532e093db8a5068a40c587915121ffaaad18.tar.gz
emacs-47d7532e093db8a5068a40c587915121ffaaad18.zip
File synchronization fixes.
* admin/CPP-DEFINES (BSD_SYSTEM, HAVE_FSYNC): Remove. * admin/merge-gnulib (GNULIB_MODULES): Add fsync, fdatasync. * configure.ac (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed. (fsync): Remove check; now done by gnulib. * lib/fdatasync.c, lib/fsync.c, m4/fdatasync.m4, m4/fsync.m4: New files, from gnulib. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * lib-src/Makefile.in (LIB_FDATASYNC): New macro. (emacsclient${EXEEXT}): Use it. * lib-src/emacsclient.c (main): Use fdatasync, not fsync, since we don't care about metadata. Keep trying if interrupted. * lib-src/movemail.c (main, popmail): Don't worry about BSD_SYSTEM, since fsync is available everywhere (or there is a substitute). Don't report an error if fsync returns EINVAL. * nt/inc/ms-w32.h (fdatasync): New macro, suggested by Eli Zaretskii. * src/Makefile.in (LIB_FDATASYNC): New macro. (LIBES): Use it. * src/conf_post.h (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed. * src/fileio.c (Fwrite_region, write_region_inhibit_fsync): Don't worry about HAVE_FSYNC, since a substitute fsync is available if the system lacks one. (Fwrite_regin): Retry fsync if interrupted. Fixes: debbugs:13944
Diffstat (limited to 'lib')
-rw-r--r--lib/fdatasync.c27
-rw-r--r--lib/fsync.c83
-rw-r--r--lib/gnulib.mk20
3 files changed, 129 insertions, 1 deletions
diff --git a/lib/fdatasync.c b/lib/fdatasync.c
new file mode 100644
index 00000000000..8f9bf15a527
--- /dev/null
+++ b/lib/fdatasync.c
@@ -0,0 +1,27 @@
1/* Emulate fdatasync on platforms that lack it.
2
3 Copyright (C) 2011-2013 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <config.h>
19#include <unistd.h>
20
21int
22fdatasync (int fd)
23{
24 /* This does more work than strictly necessary, but is the best we
25 can do portably. */
26 return fsync (fd);
27}
diff --git a/lib/fsync.c b/lib/fsync.c
new file mode 100644
index 00000000000..8a1a975049e
--- /dev/null
+++ b/lib/fsync.c
@@ -0,0 +1,83 @@
1/* Emulate fsync on platforms that lack it, primarily Windows and
2 cross-compilers like MinGW.
3
4 This is derived from sqlite3 sources.
5 http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c
6 http://www.sqlite.org/copyright.html
7
8 Written by Richard W.M. Jones <rjones.at.redhat.com>
9
10 Copyright (C) 2008-2013 Free Software Foundation, Inc.
11
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24
25#include <config.h>
26#include <unistd.h>
27
28#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
29
30/* FlushFileBuffers */
31# define WIN32_LEAN_AND_MEAN
32# include <windows.h>
33
34# include <errno.h>
35
36/* Get _get_osfhandle. */
37# include "msvc-nothrow.h"
38
39int
40fsync (int fd)
41{
42 HANDLE h = (HANDLE) _get_osfhandle (fd);
43 DWORD err;
44
45 if (h == INVALID_HANDLE_VALUE)
46 {
47 errno = EBADF;
48 return -1;
49 }
50
51 if (!FlushFileBuffers (h))
52 {
53 /* Translate some Windows errors into rough approximations of Unix
54 * errors. MSDN is useless as usual - in this case it doesn't
55 * document the full range of errors.
56 */
57 err = GetLastError ();
58 switch (err)
59 {
60 case ERROR_ACCESS_DENIED:
61 /* For a read-only handle, fsync should succeed, even though we have
62 no way to sync the access-time changes. */
63 return 0;
64
65 /* eg. Trying to fsync a tty. */
66 case ERROR_INVALID_HANDLE:
67 errno = EINVAL;
68 break;
69
70 default:
71 errno = EIO;
72 }
73 return -1;
74 }
75
76 return 0;
77}
78
79#else /* !Windows */
80
81# error "This platform lacks fsync function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
82
83#endif /* !Windows */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index c130cbc65b8..4b754ec21dd 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,7 +21,7 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdopendir filemode fstatat getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings 24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=dup --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h fdatasync fdopendir filemode fstatat fsync getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings memrchr mktime pselect pthread_sigmask putenv readlink readlinkat sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
@@ -297,6 +297,15 @@ EXTRA_DIST += fcntl.in.h
297 297
298## end gnulib module fcntl-h 298## end gnulib module fcntl-h
299 299
300## begin gnulib module fdatasync
301
302
303EXTRA_DIST += fdatasync.c
304
305EXTRA_libgnu_a_SOURCES += fdatasync.c
306
307## end gnulib module fdatasync
308
300## begin gnulib module fdopendir 309## begin gnulib module fdopendir
301 310
302 311
@@ -332,6 +341,15 @@ EXTRA_libgnu_a_SOURCES += at-func.c fstatat.c
332 341
333## end gnulib module fstatat 342## end gnulib module fstatat
334 343
344## begin gnulib module fsync
345
346
347EXTRA_DIST += fsync.c
348
349EXTRA_libgnu_a_SOURCES += fsync.c
350
351## end gnulib module fsync
352
335## begin gnulib module getgroups 353## begin gnulib module getgroups
336 354
337if gl_GNULIB_ENABLED_getgroups 355if gl_GNULIB_ENABLED_getgroups