Write tests and fixes for utimensat()

This commit is contained in:
Justine Tunney 2022-06-17 02:43:00 -07:00
parent c06ffd458c
commit d0d9cd38c5
8 changed files with 129 additions and 41 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/fmt/conv.h"
#include "libc/nt/createfile.h"
@ -34,14 +35,25 @@
textwindows int sys_utimensat_nt(int dirfd, const char *path,
const struct timespec ts[2], int flags) {
int i, rc;
int64_t fh;
int64_t fh, closeme;
uint16_t path16[PATH_MAX];
struct NtFileTime ft[2], *ftp[2];
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((fh = CreateFile(path16, kNtFileWriteAttributes, kNtFileShareRead, NULL,
kNtOpenExisting, kNtFileAttributeNormal, 0)) == -1) {
return __winerr();
if (path) {
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
if ((fh = CreateFile(path16, kNtFileWriteAttributes, kNtFileShareRead, NULL,
kNtOpenExisting, kNtFileAttributeNormal, 0)) != -1) {
closeme = fh;
} else {
return __winerr();
}
} else if (__isfdkind(dirfd, kFdFile)) {
fh = g_fds.p[dirfd].handle;
closeme = -1;
} else {
return ebadf();
}
if (!ts || ts[0].tv_nsec == UTIME_NOW || ts[1].tv_nsec == UTIME_NOW) {
GetSystemTimeAsFileTime(ft);
}
@ -65,6 +77,10 @@ textwindows int sys_utimensat_nt(int dirfd, const char *path,
} else {
rc = __winerr();
}
CloseHandle(fh);
if (closeme != -1) {
CloseHandle(fh);
}
return rc;
}