From efb8be7e82306c571dee509dbb2c5285e4360b85 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 7 Oct 2004 04:25:05 +0000 Subject: [PATCH] Added a fallback implementation of futimes. --- dlls/ntdll/file.c | 3 +-- include/wine/port.h | 5 +++++ libs/port/Makefile.in | 1 + libs/port/futimes.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 libs/port/futimes.c diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index 3ff4ffdb173..84745f105b2 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -1064,7 +1064,6 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io, struct stat st; const FILE_BASIC_INFORMATION *info = ptr; -#ifdef HAVE_FUTIMES if (info->LastAccessTime.QuadPart || info->LastWriteTime.QuadPart) { ULONGLONG sec, nsec; @@ -1095,7 +1094,7 @@ NTSTATUS WINAPI NtSetInformationFile(HANDLE handle, PIO_STATUS_BLOCK io, } if (futimes( fd, tv ) == -1) io->u.Status = FILE_GetNtStatus(); } -#endif /* HAVE_FUTIMES */ + if (io->u.Status == STATUS_SUCCESS && info->FileAttributes) { if (fstat( fd, &st ) == -1) io->u.Status = FILE_GetNtStatus(); diff --git a/include/wine/port.h b/include/wine/port.h index c1d18d9a7a2..5f98c6c84e7 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -282,6 +282,10 @@ extern int getopt_long_only (int ___argc, char *const *___argv, const struct option *__longopts, int *__longind); #endif /* HAVE_GETOPT_LONG */ +#ifndef HAVE_FUTIMES +int futimes(int fd, const struct timeval tv[2]); +#endif + #ifndef HAVE_GETPAGESIZE size_t getpagesize(void); #endif /* HAVE_GETPAGESIZE */ @@ -427,6 +431,7 @@ extern long interlocked_xchg_add( long *dest, long incr ); #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs) +#define futimes __WINE_NOT_PORTABLE(futimes) #define getopt_long __WINE_NOT_PORTABLE(getopt_long) #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only) #define getpagesize __WINE_NOT_PORTABLE(getpagesize) diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in index 57ad743e522..388da078922 100644 --- a/libs/port/Makefile.in +++ b/libs/port/Makefile.in @@ -8,6 +8,7 @@ MODULE = libwine_port.a C_SRCS = \ fstatvfs.c \ + futimes.c \ getopt.c \ getopt1.c \ getpagesize.c \ diff --git a/libs/port/futimes.c b/libs/port/futimes.c new file mode 100644 index 00000000000..923dc9a83a6 --- /dev/null +++ b/libs/port/futimes.c @@ -0,0 +1,51 @@ +/* + * futimes function + * + * Copyright 2004 Alexandre Julliard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#ifndef HAVE_FUTIMES + +#include +#include +#include +#include + +int futimes(int fd, const struct timeval tv[2]) +{ +#ifdef linux + char buffer[sizeof("/proc/self/fd/") + 3*sizeof(int)]; + + sprintf( buffer, "/proc/self/fd/%u", fd ); + if (tv) + { + struct utimbuf ut; + ut.actime = tv[0].tv_sec + (tv[0].tv_usec + 500000) / 1000000; + ut.modtime = tv[1].tv_sec + (tv[1].tv_usec + 500000) / 1000000; + return utime( buffer, &ut ); + } + else return utime( buffer, NULL ); +#else + errno = ENOSYS; + return -1; +#endif +} + +#endif /* HAVE_FUTIMES */