From: corinna Date: Tue, 29 May 2007 17:25:36 +0000 (+0000) Subject: * dtable.cc (dtable::set_file_pointers_for_exec): Call SetFilePointer X-Git-Tag: preoverlapped~457 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e2b334af662fbe2017b2d4b0c2c8e667f24631e5;p=pf3gnuchains%2Fpf3gnuchains4x.git * dtable.cc (dtable::set_file_pointers_for_exec): Call SetFilePointer correctly for 64 bit file access. Comment out functionality. * fhandler.cc (fhandler_base::open): Don't set append_mode. (fhandler_base::write): Check for O_APPEND instead of append_mode. Call SetFilePointer correctly for 64 bit file access. Handle errors from SetFilePointer. * fhandler.h (class fhandler_base): Drop append_mode status flag. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Handle seeking correctly for 64 bit file access. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 2b72ec8df3..3907da4673 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2007-05-29 Corinna Vinschen + + * dtable.cc (dtable::set_file_pointers_for_exec): Call SetFilePointer + correctly for 64 bit file access. Comment out functionality. + * fhandler.cc (fhandler_base::open): Don't set append_mode. + (fhandler_base::write): Check for O_APPEND instead of append_mode. + Call SetFilePointer correctly for 64 bit file access. Handle + errors from SetFilePointer. + * fhandler.h (class fhandler_base): Drop append_mode status flag. + * fhandler_disk_file.cc (fhandler_base::fstat_helper): Handle + seeking correctly for 64 bit file access. + 2007-05-22 Corinna Vinschen * path.cc (cwdstuff::set): Revert useless acquire check. diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 17efacb697..c40b5e6ae7 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -690,12 +690,16 @@ dtable::fixup_before_exec (DWORD target_proc_id) void dtable::set_file_pointers_for_exec () { +/* This is not POSIX-compliant. */ +#if 0 + LONG off_high = 0; lock (); fhandler_base *fh; for (size_t i = 0; i < size; i++) if ((fh = fds[i]) != NULL && fh->get_flags () & O_APPEND) - SetFilePointer (fh->get_handle (), 0, 0, FILE_END); + SetFilePointer (fh->get_handle (), 0, &off_high, FILE_END); unlock (); +#endif } void diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 5f46484f9a..5490d3ab04 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -550,9 +550,6 @@ fhandler_base::open (int flags, mode_t mode) if ((flags & O_EXCL) && (flags & O_CREAT)) create_disposition = FILE_CREATE; - if (flags & O_APPEND) - append_mode (true); - if (flags & O_CREAT && get_device () == FH_FS) { file_attributes = FILE_ATTRIBUTE_NORMAL; @@ -711,8 +708,17 @@ fhandler_base::write (const void *ptr, size_t len) { int res; - if (append_mode ()) - SetFilePointer (get_output_handle (), 0, 0, FILE_END); + if (get_flags () & O_APPEND) + { + LONG off_high = 0; + DWORD ret = SetFilePointer (get_output_handle (), 0, &off_high, FILE_END); + if (ret == INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR) + { + debug_printf ("Seeking to EOF in append mode failed"); + __seterrno (); + return -1; + } + } else if (did_lseek ()) { _off64_t actual_length, current_position; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 839fc4b056..814054399b 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -101,7 +101,6 @@ class fhandler_base unsigned wbinset : 1; /* binary write mode explicitly set */ unsigned nohandle : 1; /* No handle associated with fhandler. */ unsigned uninterruptible_io : 1; /* Set if I/O should be uninterruptible. */ - unsigned append_mode : 1; /* always append */ unsigned did_lseek : 1; /* set when lseek is called as a flag that _write should check if we've moved beyond EOF, zero filling or making @@ -114,7 +113,7 @@ class fhandler_base public: status_flags () : rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0), - uninterruptible_io (0), append_mode (0), did_lseek (0), + uninterruptible_io (0), did_lseek (0), query_open (no_query), close_on_exec (0), need_fork_fixup (0) {} } status, open_status; @@ -191,7 +190,6 @@ class fhandler_base IMPLEMENT_STATUS_FLAG (bool, rbinset) IMPLEMENT_STATUS_FLAG (bool, nohandle) IMPLEMENT_STATUS_FLAG (bool, uninterruptible_io) - IMPLEMENT_STATUS_FLAG (bool, append_mode) IMPLEMENT_STATUS_FLAG (bool, did_lseek) IMPLEMENT_STATUS_FLAG (query_state, query_open) IMPLEMENT_STATUS_FLAG (bool, close_on_exec) diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index d510ff0f06..353c45ba5d 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -493,13 +493,14 @@ fhandler_base::fstat_helper (struct __stat64 *buf, if (pc.exec_state () == dont_know_if_executable) { DWORD cur, done; + LONG curhigh = 0; char magic[3]; /* First retrieve current position, set to beginning of file if not already there. */ - cur = SetFilePointer (get_handle (), 0, NULL, FILE_CURRENT); - if (cur != INVALID_SET_FILE_POINTER - && (!cur || SetFilePointer (get_handle (), 0, NULL, FILE_BEGIN) + cur = SetFilePointer (get_handle (), 0, &curhigh, FILE_CURRENT); + if ((cur != INVALID_SET_FILE_POINTER || GetLastError () == NO_ERROR) + && ((!cur && !curhigh) || SetFilePointer (get_handle (), 0, NULL, FILE_BEGIN) != INVALID_SET_FILE_POINTER)) { /* FIXME should we use /etc/magic ? */ @@ -510,7 +511,7 @@ fhandler_base::fstat_helper (struct __stat64 *buf, pc.set_exec (); buf->st_mode |= STD_XBITS; } - SetFilePointer (get_handle (), cur, NULL, FILE_BEGIN); + SetFilePointer (get_handle (), cur, &curhigh, FILE_BEGIN); } } }