Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2005-02-20 14:44:32 +0300
committerCorinna Vinschen <corinna@vinschen.de>2005-02-20 14:44:32 +0300
commit2b09be25a3929c8c6d7e23e1abb4756187c5036b (patch)
tree7a40cce415e163ca50fc27e15858f5da0544d3f6 /winsup/cygwin/times.cc
parent731028b3266ad7660095fbae3d94ce5cb9b378b0 (diff)
* fhandler.h (enum query_state): Add query_write_attributes state.
(fhandler_base::status.query_open): Add a bit to make room for more states. (class fhandler_base): Declare new method utimes. (class fhandler_socket): Ditto. (class fhandler_disk_file): Ditto. (fhandler_disk_file::fhandler_disk_file): Add constructor with path_conv parameter. * fhandler.cc (fhandler_base::open): Add query_write_attributes handling. (fhandler_base::utimes): New method. * fhandler_disk_file.cc (fhandler_disk_file::link): Simplify. Open file with query_write_attributes instead of query_write_control. (fhandler_disk_file::utimes): New method. (fhandler_disk_file::fhandler_disk_file): Add constructor with path_conv parameter setting pc member immediately. * fhandler_socket.cc (fhandler_socket::fchmod): Use new fhandler_disk_file constructor. (fhandler_socket::fchown): Ditto. (fhandler_socket::facl): Ditto. (fhandler_socket::link): Ditto. (fhandler_socket::utimes): New method. * times.cc: Include dtable.h. (timeval_to_filetime): Make non-static. (utimes): Move functionality into fhandler method utimes. Just call this method from here. * winsup.h: Simplify declarations of time helper functions. (timeval_to_filetime): Add extern declaration.
Diffstat (limited to 'winsup/cygwin/times.cc')
-rw-r--r--winsup/cygwin/times.cc93
1 files changed, 14 insertions, 79 deletions
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index 1e1a90abd..5e4496308 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -21,6 +21,7 @@ details. */
#include "security.h"
#include "path.h"
#include "fhandler.h"
+#include "dtable.h"
#include "pinfo.h"
#include "hires.h"
#include "cygtls.h"
@@ -30,8 +31,6 @@ details. */
#define FACTOR (0x19db1ded53e8000LL)
#define NSPERSEC 10000000LL
-static void __stdcall timeval_to_filetime (const struct timeval *time, FILETIME *out);
-
/* Cygwin internal */
static unsigned long long __stdcall
__to_clock_t (FILETIME * src, int flag)
@@ -184,7 +183,7 @@ time_t_to_filetime (time_t time_in, FILETIME *out)
}
/* Cygwin internal */
-static void __stdcall
+void __stdcall
timeval_to_filetime (const struct timeval *time_in, FILETIME *out)
{
long long x = time_in->tv_sec * NSPERSEC +
@@ -444,91 +443,27 @@ gmtime (const time_t *tim_p)
#endif /* POSIX_LOCALTIME */
-/* utimes: standards? */
+/* utimes: POSIX/SUSv3 */
extern "C" int
utimes (const char *path, const struct timeval *tvp)
{
- int res = 0;
- struct timeval tmp[2];
- path_conv win32 (path);
+ int res = -1;
+ fhandler_base *fh;
- if (win32.error)
- {
- set_errno (win32.error);
- syscall_printf ("-1 = utimes (%s, %x)", path, tvp);
- return -1;
- }
+ if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW)))
+ goto error;
- /* MSDN suggests using FILE_FLAG_BACKUP_SEMANTICS for accessing
- the times of directories. */
- /* Note: It's documented in MSDN that FILE_WRITE_ATTRIBUTES is
- sufficient to change the timestamps. Unfortunately it's not
- sufficient for a remote HPFS which requires GENERIC_WRITE.
- Since we don't trust the weird FS name "??SS", we just try to
- open with GENERIC_WRITE if opening with FILE_WRITE_ATTRIBUTES
- failed. That should do it, though this fails for R/O files
- of course. */
- HANDLE h = CreateFile (win32, FILE_WRITE_ATTRIBUTES,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- &sec_none_nih, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
- 0);
- if (h == INVALID_HANDLE_VALUE)
- h = CreateFile (win32, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
- &sec_none_nih, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0);
-
- if (h == INVALID_HANDLE_VALUE)
+ if (fh->error ())
{
- if (win32.isdir ())
- {
- /* What we can do with directories more? */
- res = 0;
- }
- else
- {
- res = -1;
- __seterrno ();
- }
+ debug_printf ("got %d error from build_fh_name", fh->error ());
+ set_errno (fh->error ());
}
else
- {
- gettimeofday (&tmp[0], 0);
- if (tvp == 0)
- {
- tmp[1] = tmp[0];
- tvp = tmp;
- }
-
- FILETIME lastaccess;
- FILETIME lastwrite;
- FILETIME lastchange;
-
- timeval_to_filetime (tvp + 0, &lastaccess);
- timeval_to_filetime (tvp + 1, &lastwrite);
- /* Update st_ctime */
- timeval_to_filetime (tmp + 0, &lastchange);
-
- debug_printf ("incoming lastaccess %08x %08x",
- tvp->tv_sec,
- tvp->tv_usec);
-
- /* FIXME: SetFileTime needs a handle with a write lock
- on the file whose time is being modified. So calls to utime()
- fail for read only files. */
-
- if (!SetFileTime (h, &lastchange, &lastaccess, &lastwrite))
- {
- __seterrno ();
- res = -1;
- }
- else
- res = 0;
- CloseHandle (h);
- }
+ res = fh->utimes (tvp);
- syscall_printf ("%d = utimes (%s, %x); (h%d)",
- res, path, tvp, h);
+ delete fh;
+ error:
+ syscall_printf ("%d = utimes (%s, %p)", res, path, tvp);
return res;
}