summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2005-05-18 18:02:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:56:56 -0500
commitfe0ce8dd8e18de6110404661f26db7a66ebac5ad (patch)
treefdc3855c259384f7773d3e6d9054b282d81a8553 /source3/lib/util.c
parent3b0df6770db55a7690473547bef29a5a7bede0b9 (diff)
downloadsamba-fe0ce8dd8e18de6110404661f26db7a66ebac5ad.tar.gz
samba-fe0ce8dd8e18de6110404661f26db7a66ebac5ad.tar.bz2
samba-fe0ce8dd8e18de6110404661f26db7a66ebac5ad.zip
r6890: Refactor printing interface to take offset into job. Fixes bug
where large print jobs can have out-of-order offsets. Bug found by Arcady Chernyak <Arcady.Chernyak@efi.com> Jeremy. (This used to be commit 482f7e0e3706098b71aa0b31a134994acb1e9fcf)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index f31bcef281..f92ffaedc0 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -640,6 +640,46 @@ void close_low_fds(BOOL stderr_too)
#endif
}
+/*******************************************************************
+ Write data into an fd at a given offset. Ignore seek errors.
+********************************************************************/
+
+ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, SMB_OFF_T pos)
+{
+ size_t total=0;
+ ssize_t ret;
+
+ if (pos == (SMB_OFF_T)-1) {
+ return write_data(fd, buffer, N);
+ }
+#if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
+ while (total < N) {
+ ret = sys_pwrite(fd,buffer + total,N - total, pos);
+ if (ret == -1 && errno == ESPIPE) {
+ return write_data(fd, buffer + total,N - total);
+ }
+ if (ret == -1) {
+ DEBUG(0,("write_data_at_offset: write failure. Error = %s\n", strerror(errno) ));
+ return -1;
+ }
+ if (ret == 0) {
+ return total;
+ }
+ total += ret;
+ pos += ret;
+ }
+ return (ssize_t)total;
+#else
+ /* Use lseek and write_data. */
+ if (sys_lseek(fd, pos, SEEK_SET) == -1) {
+ if (errno != ESPIPE) {
+ return -1;
+ }
+ }
+ return write_data(fd, buffer, N);
+#endif
+}
+
/****************************************************************************
Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
else