diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/fdatasync.c | 27 | ||||
| -rw-r--r-- | lib/fsync.c | 83 | ||||
| -rw-r--r-- | lib/gnulib.mk | 20 | ||||
| -rw-r--r-- | lib/putenv.c | 82 | ||||
| -rw-r--r-- | lib/unistd.in.h | 4 |
5 files changed, 174 insertions, 42 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 | |||
| 21 | int | ||
| 22 | fdatasync (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 | |||
| 39 | int | ||
| 40 | fsync (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 | ||
| 27 | MOSTLYCLEANFILES += core *.stackdump | 27 | MOSTLYCLEANFILES += 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 | |||
| 303 | EXTRA_DIST += fdatasync.c | ||
| 304 | |||
| 305 | EXTRA_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 | |||
| 347 | EXTRA_DIST += fsync.c | ||
| 348 | |||
| 349 | EXTRA_libgnu_a_SOURCES += fsync.c | ||
| 350 | |||
| 351 | ## end gnulib module fsync | ||
| 352 | |||
| 335 | ## begin gnulib module getgroups | 353 | ## begin gnulib module getgroups |
| 336 | 354 | ||
| 337 | if gl_GNULIB_ENABLED_getgroups | 355 | if gl_GNULIB_ENABLED_getgroups |
diff --git a/lib/putenv.c b/lib/putenv.c index ed666afc3bb..5461273084e 100644 --- a/lib/putenv.c +++ b/lib/putenv.c | |||
| @@ -62,7 +62,9 @@ static int | |||
| 62 | _unsetenv (const char *name) | 62 | _unsetenv (const char *name) |
| 63 | { | 63 | { |
| 64 | size_t len; | 64 | size_t len; |
| 65 | #if !HAVE_DECL__PUTENV | ||
| 65 | char **ep; | 66 | char **ep; |
| 67 | #endif | ||
| 66 | 68 | ||
| 67 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | 69 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) |
| 68 | { | 70 | { |
| @@ -72,7 +74,7 @@ _unsetenv (const char *name) | |||
| 72 | 74 | ||
| 73 | len = strlen (name); | 75 | len = strlen (name); |
| 74 | 76 | ||
| 75 | #if HAVE__PUTENV | 77 | #if HAVE_DECL__PUTENV |
| 76 | { | 78 | { |
| 77 | int putenv_result, putenv_errno; | 79 | int putenv_result, putenv_errno; |
| 78 | char *name_ = malloc (len + 2); | 80 | char *name_ = malloc (len + 2); |
| @@ -125,46 +127,46 @@ putenv (char *string) | |||
| 125 | return _unsetenv (string); | 127 | return _unsetenv (string); |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | #if HAVE__PUTENV | 130 | #if HAVE_DECL__PUTENV |
| 129 | /* Rely on _putenv to allocate the new environment. If other | 131 | /* Rely on _putenv to allocate the new environment. If other |
| 130 | parts of the application use _putenv, the !HAVE__PUTENV code | 132 | parts of the application use _putenv, the !HAVE_DECL__PUTENV code |
| 131 | would fight over who owns the environ vector, causing a crash. */ | 133 | would fight over who owns the environ vector, causing a crash. */ |
| 132 | if (name_end[1]) | 134 | if (name_end[1]) |
| 133 | return _putenv (string); | 135 | return _putenv (string); |
| 134 | else | 136 | else |
| 135 | { | 137 | { |
| 136 | /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") | 138 | /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") |
| 137 | to allocate the environ vector and then replace the new | 139 | to allocate the environ vector and then replace the new |
| 138 | entry with "NAME=". */ | 140 | entry with "NAME=". */ |
| 139 | int putenv_result, putenv_errno; | 141 | int putenv_result, putenv_errno; |
| 140 | char *name_x = malloc (name_end - string + sizeof "= "); | 142 | char *name_x = malloc (name_end - string + sizeof "= "); |
| 141 | if (!name_x) | 143 | if (!name_x) |
| 142 | return -1; | 144 | return -1; |
| 143 | memcpy (name_x, string, name_end - string + 1); | 145 | memcpy (name_x, string, name_end - string + 1); |
| 144 | name_x[name_end - string + 1] = ' '; | 146 | name_x[name_end - string + 1] = ' '; |
| 145 | name_x[name_end - string + 2] = 0; | 147 | name_x[name_end - string + 2] = 0; |
| 146 | putenv_result = _putenv (name_x); | 148 | putenv_result = _putenv (name_x); |
| 147 | putenv_errno = errno; | 149 | putenv_errno = errno; |
| 148 | for (ep = environ; *ep; ep++) | 150 | for (ep = environ; *ep; ep++) |
| 149 | if (strcmp (*ep, name_x) == 0) | 151 | if (strcmp (*ep, name_x) == 0) |
| 150 | { | 152 | { |
| 151 | *ep = string; | 153 | *ep = string; |
| 152 | break; | 154 | break; |
| 153 | } | 155 | } |
| 154 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 156 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 155 | if (putenv_result == 0) | 157 | if (putenv_result == 0) |
| 156 | { | 158 | { |
| 157 | /* _putenv propagated "NAME= " into the subprocess environment; | 159 | /* _putenv propagated "NAME= " into the subprocess environment; |
| 158 | fix that by calling SetEnvironmentVariable directly. */ | 160 | fix that by calling SetEnvironmentVariable directly. */ |
| 159 | name_x[name_end - string] = 0; | 161 | name_x[name_end - string] = 0; |
| 160 | putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; | 162 | putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; |
| 161 | putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ | 163 | putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ |
| 162 | } | ||
| 163 | # endif | ||
| 164 | free (name_x); | ||
| 165 | __set_errno (putenv_errno); | ||
| 166 | return putenv_result; | ||
| 167 | } | 164 | } |
| 165 | # endif | ||
| 166 | free (name_x); | ||
| 167 | __set_errno (putenv_errno); | ||
| 168 | return putenv_result; | ||
| 169 | } | ||
| 168 | #else | 170 | #else |
| 169 | for (ep = environ; *ep; ep++) | 171 | for (ep = environ; *ep; ep++) |
| 170 | if (strncmp (*ep, string, name_end - string) == 0 | 172 | if (strncmp (*ep, string, name_end - string) == 0 |
| @@ -186,7 +188,7 @@ putenv (char *string) | |||
| 186 | last_environ = new_environ; | 188 | last_environ = new_environ; |
| 187 | environ = new_environ; | 189 | environ = new_environ; |
| 188 | } | 190 | } |
| 189 | #endif | ||
| 190 | 191 | ||
| 191 | return 0; | 192 | return 0; |
| 193 | #endif | ||
| 192 | } | 194 | } |
diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 675c7e6a552..2ea9af43652 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h | |||
| @@ -61,8 +61,10 @@ | |||
| 61 | /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in | 61 | /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in |
| 62 | <unistd.h>. */ | 62 | <unistd.h>. */ |
| 63 | /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ | 63 | /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ |
| 64 | /* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is | ||
| 65 | included here. */ | ||
| 64 | /* But avoid namespace pollution on glibc systems. */ | 66 | /* But avoid namespace pollution on glibc systems. */ |
| 65 | #ifndef __GLIBC__ | 67 | #if !defined __GLIBC__ && !defined __osf__ |
| 66 | # define __need_system_stdlib_h | 68 | # define __need_system_stdlib_h |
| 67 | # include <stdlib.h> | 69 | # include <stdlib.h> |
| 68 | # undef __need_system_stdlib_h | 70 | # undef __need_system_stdlib_h |