Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/pwrite.c @ 17102:9e72d3927af1
binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline'
* lib/binary-io.c, lib/eealloc.c, lib/mbfile.c, lib/mbiter.c:
* lib/mbuiter.c, lib/xsize.c: New files.
* lib/binary-io.h (BINARY_IO_INLINE):
* lib/eealloc.h (EEALLOC_INLINE):
* lib/mbfile.h (MBFILE_INLINE):
* lib/mbiter.h (MBITER_INLINE):
* lib/mbuiter.h (MBUITER_INLINE):
* lib/xsize.h (XSIZE_INLINE):
New macros.
Replace all uses of 'static inline' with them.
Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
* m4/eealloc.m4 (gl_EEALLOC):
* m4/mbfile.m4 (gl_MBFILE):
* m4/mbiter.m4 (gl_MBITER):
* m4/xsize.m4 (gl_XSIZE):
Do not require AC_C_INLINE.
* modules/binary-io (Files, lib_SOURCES): Add lib/binary-io.c
* modules/eealloc (Files, lib_SOURCES): Add lib/eealloc.c.
* modules/mbfile (Files, lib_SOURCES): Add lib/mbfile.c.
* modules/mbiter (Files, lib_SOURCES): Add lib/mbiter.c.
* modules/mbuiter (Files, lib_SOURCES): Add lib/mbuiter.c.
* modules/xsize (Files, lib_SOURCES): Add lib/xsize.c.
* modules/binary-io, modules/eealloc, modules/mbfile:
* modules/mbiter, modules/mbuiter:
(Depends-on): Add extern-inline.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 29 Aug 2012 23:13:42 -0700 |
parents | 8250f2777afc |
children | e542fd46ad6f |
rev | line source |
---|---|
13314 | 1 /* Write block to given position in file without changing file pointer. |
2 POSIX version. | |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14086
diff
changeset
|
3 Copyright (C) 1997-1999, 2002, 2011-2012 Free Software Foundation, Inc. |
13314 | 4 This file is part of the GNU C Library. |
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. | |
6 | |
7 This program is free software: you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 3 of the License, or | |
10 (at your option) any later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | |
20 #include <config.h> | |
21 | |
22 /* Specification. */ | |
23 #include <unistd.h> | |
24 | |
25 #include <errno.h> | |
26 | |
14086
b3fb554bb012
pwrite: Fix test whether it works and make it work on HP-UX 11.11.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
27 #define __libc_lseek(f,o,w) lseek (f, o, w) |
b3fb554bb012
pwrite: Fix test whether it works and make it work on HP-UX 11.11.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
28 #define __set_errno(Val) errno = (Val) |
b3fb554bb012
pwrite: Fix test whether it works and make it work on HP-UX 11.11.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
29 #define __libc_write(f,b,n) write (f, b, n) |
13314 | 30 |
31 /* Note: This implementation of pwrite is not multithread-safe. */ | |
32 | |
33 ssize_t | |
34 pwrite (int fd, const void *buf, size_t nbyte, off_t offset) | |
35 { | |
36 /* Since we must not change the file pointer preserve the value so that | |
37 we can restore it later. */ | |
38 int save_errno; | |
39 ssize_t result; | |
40 off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR); | |
41 if (old_offset == (off_t) -1) | |
42 return -1; | |
43 | |
44 /* Set to wanted position. */ | |
45 if (__libc_lseek (fd, offset, SEEK_SET) == (off_t) -1) | |
46 return -1; | |
47 | |
48 /* Write out the data. */ | |
49 result = __libc_write (fd, buf, nbyte); | |
50 | |
51 /* Now we have to restore the position. If this fails we have to | |
52 return this as an error. But if the writing also failed we | |
53 return this error. */ | |
54 save_errno = errno; | |
55 if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1) | |
56 { | |
57 if (result == -1) | |
13479
8a0b8adde2be
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
13314
diff
changeset
|
58 __set_errno (save_errno); |
13314 | 59 return -1; |
60 } | |
61 __set_errno (save_errno); | |
62 | |
63 return result; | |
64 } |