VirtualBox

source: kBuild/trunk/src/lib/nt/ntutimes.c@ 3372

Last change on this file since 3372 was 3097, checked in by bird, 7 years ago

utime/lutime windows emulation fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1/* $Id: ntutimes.c 3097 2017-10-14 03:52:44Z bird $ */
2/** @file
3 * MSC + NT utimes and lutimes
4 */
5
6/*
7 * Copyright (c) 2005-2017 knut st. osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 *
27 * Alternatively, the content of this file may be used under the terms of the
28 * GPL version 2 or later, or LGPL version 2.1 or later.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "ntutimes.h"
36
37#include "ntstuff.h"
38#include "nthlp.h"
39
40
41
42static int birdUtimesInternal(const char *pszPath, BirdTimeVal_T paTimes[2], int fFollowLink)
43{
44 HANDLE hFile = birdOpenFileEx(NULL,
45 pszPath,
46 FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
47 FILE_ATTRIBUTE_NORMAL,
48 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
49 FILE_OPEN,
50 FILE_OPEN_FOR_BACKUP_INTENT | (fFollowLink ? 0 : FILE_OPEN_REPARSE_POINT),
51 OBJ_CASE_INSENSITIVE);
52 if (hFile != INVALID_HANDLE_VALUE)
53 {
54 MY_FILE_BASIC_INFORMATION Info;
55 MY_IO_STATUS_BLOCK Ios;
56 MY_NTSTATUS rcNt;
57
58 memset(&Info, 0, sizeof(Info));
59 if (paTimes)
60 {
61 Info.LastAccessTime.QuadPart = birdNtTimeFromTimeVal(&paTimes[0]);
62 Info.LastWriteTime.QuadPart = birdNtTimeFromTimeVal(&paTimes[1]);
63 }
64 else
65 {
66 /** @todo replace this with something from ntdll */
67 FILETIME Now;
68 GetSystemTimeAsFileTime(&Now);
69 Info.LastAccessTime.HighPart = Now.dwHighDateTime;
70 Info.LastAccessTime.LowPart = Now.dwLowDateTime;
71 Info.LastWriteTime.HighPart = Now.dwHighDateTime;
72 Info.LastWriteTime.LowPart = Now.dwLowDateTime;
73 }
74
75 Ios.Information = -1;
76 Ios.u.Status = -1;
77
78 rcNt = g_pfnNtSetInformationFile(hFile, &Ios, &Info, sizeof(Info), MyFileBasicInformation);
79
80 birdCloseFile(hFile);
81
82 if (MY_NT_SUCCESS(rcNt))
83 return 0;
84 birdSetErrnoFromNt(rcNt);
85 }
86 return -1;
87}
88
89
90int birdUtimes(const char *pszFile, BirdTimeVal_T paTimes[2])
91{
92 return birdUtimesInternal(pszFile, paTimes, 1 /*fFollowLink*/);
93}
94
95int birdLUtimes(const char *pszFile, BirdTimeVal_T paTimes[2])
96{
97 return birdUtimesInternal(pszFile, paTimes, 0 /*fFollowLink*/);
98}
99
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette