summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-06-05 09:21:39 +0000
committerCorinna Vinschen <corinna@vinschen.de>2001-06-05 09:21:39 +0000
commitfa821be37b56798f70b488530a07adeb2092b69b (patch)
tree7b998e8c103a40a6b6f390fe72e6842b9924d1ee /winsup/cygwin/fhandler.cc
parent2c1296f8565c55177449fbae7cc365700726a890 (diff)
downloadcygnal-fa821be37b56798f70b488530a07adeb2092b69b.tar.gz
cygnal-fa821be37b56798f70b488530a07adeb2092b69b.tar.bz2
cygnal-fa821be37b56798f70b488530a07adeb2092b69b.zip
* fhandler.cc (fhandler_disk_file::fstat): Always reset file position
to original value after checking for executable magic.
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 15e0e2303..5c613bccd 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -974,16 +974,23 @@ fhandler_disk_file::fstat (struct stat *buf)
buf->st_mode |= S_IFREG;
if (!dont_care_if_execable () && !get_execable_p ())
{
- DWORD done;
+ DWORD cur, done;
char magic[3];
- /* FIXME should we use /etc/magic ? */
- magic[0] = magic[1] = magic[2] = '\0';
- if (ReadFile (get_handle (), magic, 3, &done, 0)
- && done == 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)
+ != INVALID_SET_FILE_POINTER))
{
- if (has_exec_chars (magic, done))
- set_execable_p ();
- SetFilePointer (get_handle(), -(LONG) done, NULL, FILE_CURRENT);
+ /* FIXME should we use /etc/magic ? */
+ magic[0] = magic[1] = magic[2] = '\0';
+ if (ReadFile (get_handle (), magic, 3, &done, 0) &&
+ done == 3 && has_exec_chars (magic, done))
+ set_execable_p ();
+ SetFilePointer (get_handle(), cur, NULL, FILE_BEGIN);
}
}
if (get_execable_p ())