2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-01-30 09:49:43 +00:00
|
|
|
#include "libc/bits/weaken.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/calls/calls.h"
|
|
|
|
#include "libc/calls/internal.h"
|
|
|
|
#include "libc/errno.h"
|
2021-05-14 12:36:58 +00:00
|
|
|
#include "libc/intrin/asan.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/sysv/consts/at.h"
|
2021-05-14 12:36:58 +00:00
|
|
|
#include "libc/sysv/errfuns.h"
|
2021-01-30 09:49:43 +00:00
|
|
|
#include "libc/zipos/zipos.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-30 09:49:43 +00:00
|
|
|
* Returns information about thing.
|
2020-06-15 14:18:57 +00:00
|
|
|
*
|
2021-01-30 09:49:43 +00:00
|
|
|
* @param dirfd is normally AT_FDCWD but if it's an open directory and
|
|
|
|
* file is a relative path, then file becomes relative to dirfd
|
|
|
|
* @param st is where result is stored
|
2020-06-15 14:18:57 +00:00
|
|
|
* @param flags can have AT_{EMPTY_PATH,NO_AUTOMOUNT,SYMLINK_NOFOLLOW}
|
|
|
|
* @return 0 on success, or -1 w/ errno
|
2021-01-30 09:49:43 +00:00
|
|
|
* @see S_ISDIR(st.st_mode), S_ISREG()
|
2020-06-15 14:18:57 +00:00
|
|
|
* @asyncsignalsafe
|
|
|
|
*/
|
2021-01-30 09:49:43 +00:00
|
|
|
int fstatat(int dirfd, const char *path, struct stat *st, uint32_t flags) {
|
|
|
|
struct ZiposUri zipname;
|
2021-05-14 12:36:58 +00:00
|
|
|
if (IsAsan() && (!st || !__asan_is_valid(st, sizeof(*st)))) return efault();
|
2021-01-30 09:49:43 +00:00
|
|
|
if (weaken(__zipos_stat) && weaken(__zipos_parseuri)(path, &zipname) != -1) {
|
|
|
|
return weaken(__zipos_stat)(&zipname, st);
|
|
|
|
} else if (!IsWindows()) {
|
2021-02-04 03:35:29 +00:00
|
|
|
return sys_fstatat(dirfd, path, st, flags);
|
2021-01-30 09:49:43 +00:00
|
|
|
} else {
|
2021-02-04 03:35:29 +00:00
|
|
|
return sys_fstatat_nt(dirfd, path, st, flags);
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|
|
|
|
}
|