| 1 | /* $Id: ntutimes.c 3060 2017-09-21 15:11:07Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * MSC + NT utimes and lutimes
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2005-2017 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 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 |
|
|---|
| 42 | static int birdUtimesInternal(const char *pszPath, BirdTimeVal_T paTimes[2], int fFollowLink)
|
|---|
| 43 | {
|
|---|
| 44 | HANDLE hFile = birdOpenFileEx(NULL,
|
|---|
| 45 | pszPath,
|
|---|
| 46 | FILE_WRITE_ATTRIBUTES,
|
|---|
| 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(0));
|
|---|
| 59 | Info.LastAccessTime.QuadPart = birdNtTimeFromTimeVal(&paTimes[0]);
|
|---|
| 60 | Info.LastWriteTime.QuadPart = birdNtTimeFromTimeVal(&paTimes[1]);
|
|---|
| 61 |
|
|---|
| 62 | Ios.Information = -1;
|
|---|
| 63 | Ios.u.Status = -1;
|
|---|
| 64 |
|
|---|
| 65 | rcNt = g_pfnNtSetInformationFile(hFile, &Ios, &Info, sizeof(Info), MyFileBasicInformation);
|
|---|
| 66 |
|
|---|
| 67 | birdCloseFile(hFile);
|
|---|
| 68 |
|
|---|
| 69 | if (MY_NT_SUCCESS(rcNt))
|
|---|
| 70 | return 0;
|
|---|
| 71 | birdSetErrnoFromNt(rcNt);
|
|---|
| 72 | }
|
|---|
| 73 | return -1;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | int birdUtimes(const char *pszFile, BirdTimeVal_T paTimes[2])
|
|---|
| 78 | {
|
|---|
| 79 | return birdUtimesInternal(pszFile, paTimes, 1 /*fFollowLink*/);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | int birdLUtimes(const char *pszFile, BirdTimeVal_T paTimes[2])
|
|---|
| 83 | {
|
|---|
| 84 | return birdUtimesInternal(pszFile, paTimes, 0 /*fFollowLink*/);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|