[2989] | 1 | /* $Id: fts-nt.h 3535 2021-12-20 23:32:28Z bird $ */
|
---|
[2985] | 2 | /** @file
|
---|
| 3 | * Header for the NT port of BSD fts.h.
|
---|
| 4 | *
|
---|
| 5 | * @copyright Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved.
|
---|
| 6 | * @copyright NT modifications Copyright (C) 2016 knut st. osmundsen <bird-klibc-spam-xiv@anduin.net>
|
---|
| 7 | * @licenses BSD3
|
---|
| 8 | */
|
---|
| 9 |
|
---|
[2983] | 10 | /*
|
---|
| 11 | * Copyright (c) 1989, 1993
|
---|
| 12 | * The Regents of the University of California. All rights reserved.
|
---|
| 13 | *
|
---|
| 14 | * Redistribution and use in source and binary forms, with or without
|
---|
| 15 | * modification, are permitted provided that the following conditions
|
---|
| 16 | * are met:
|
---|
| 17 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 18 | * notice, this list of conditions and the following disclaimer.
|
---|
| 19 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 20 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 21 | * documentation and/or other materials provided with the distribution.
|
---|
| 22 | * 3. Neither the name of the University nor the names of its contributors
|
---|
| 23 | * may be used to endorse or promote products derived from this software
|
---|
| 24 | * without specific prior written permission.
|
---|
| 25 | *
|
---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 36 | * SUCH DAMAGE.
|
---|
| 37 | *
|
---|
| 38 | * @(#)fts.h 8.3 (Berkeley) 8/14/94
|
---|
| 39 | * $FreeBSD$
|
---|
[2985] | 40 | *
|
---|
[2983] | 41 | */
|
---|
| 42 |
|
---|
[2985] | 43 | #ifndef INCLUDED_FTS_NT_H
|
---|
| 44 | #define INCLUDED_FTS_NT_H
|
---|
[2983] | 45 |
|
---|
[2985] | 46 | #include <sys/types.h>
|
---|
| 47 | #include <stdint.h>
|
---|
| 48 | #include "ntstat.h" /* ensure correct stat structure */
|
---|
[2983] | 49 |
|
---|
[2985] | 50 | typedef uint64_t fts_dev_t;
|
---|
| 51 | typedef uint64_t fts_ino_t;
|
---|
| 52 | typedef uint32_t fts_nlink_t;
|
---|
| 53 | #ifdef _WINNT_
|
---|
| 54 | typedef HANDLE fts_fd_t;
|
---|
[2997] | 55 | # define NT_FTS_INVALID_HANDLE_VALUE INVALID_HANDLE_VALUE
|
---|
[2985] | 56 | #else
|
---|
| 57 | typedef void * fts_fd_t;
|
---|
[2997] | 58 | # define NT_FTS_INVALID_HANDLE_VALUE ((void *)~(uintptr_t)0)
|
---|
[2985] | 59 | #endif
|
---|
| 60 | #define FTSCALL __cdecl
|
---|
| 61 |
|
---|
[2983] | 62 | typedef struct {
|
---|
| 63 | struct _ftsent *fts_cur; /* current node */
|
---|
| 64 | struct _ftsent *fts_child; /* linked list of children */
|
---|
| 65 | struct _ftsent **fts_array; /* sort array */
|
---|
[2985] | 66 | fts_dev_t fts_dev; /* starting device # */
|
---|
[2983] | 67 | char *fts_path; /* path for this descent */
|
---|
[2985] | 68 | size_t fts_pathlen; /* sizeof(path) */
|
---|
[2998] | 69 | wchar_t *fts_wcspath; /* NT: UTF-16 path for this descent. */
|
---|
| 70 | size_t fts_cwcpath; /* NT: size of fts_wcspath buffer */
|
---|
[2985] | 71 | size_t fts_nitems; /* elements in the sort array */
|
---|
| 72 | int (FTSCALL *fts_compar) /* compare function */
|
---|
[2983] | 73 | (const struct _ftsent * const *, const struct _ftsent * const *);
|
---|
| 74 |
|
---|
| 75 | #define FTS_COMFOLLOW 0x001 /* follow command line symlinks */
|
---|
| 76 | #define FTS_LOGICAL 0x002 /* logical walk */
|
---|
| 77 | #define FTS_NOCHDIR 0x004 /* don't change directories */
|
---|
| 78 | #define FTS_NOSTAT 0x008 /* don't get stat info */
|
---|
| 79 | #define FTS_PHYSICAL 0x010 /* physical walk */
|
---|
| 80 | #define FTS_SEEDOT 0x020 /* return dot and dot-dot */
|
---|
| 81 | #define FTS_XDEV 0x040 /* don't cross devices */
|
---|
[2985] | 82 | #if 0 /* No whiteout on NT. */
|
---|
[2983] | 83 | #define FTS_WHITEOUT 0x080 /* return whiteout information */
|
---|
[2985] | 84 | #endif
|
---|
[3535] | 85 | #define FTS_CWDFD 0x100 /* For gnulib fts compatibility, enables fts_cwd_fd. */
|
---|
| 86 | #define FTS_TIGHT_CYCLE_CHECK 0x200 /* Ignored currently */
|
---|
[3004] | 87 | #define FTS_NO_ANSI 0x40000000 /* NT: No ansi name or access path. */
|
---|
[3535] | 88 | #define FTS_OPTIONMASK 0x400003ff /* valid user option mask */
|
---|
[2983] | 89 |
|
---|
[3535] | 90 | #define FTS_NAMEONLY 0x10000 /* (private) child names only */
|
---|
| 91 | #define FTS_STOP 0x20000 /* (private) unrecoverable error */
|
---|
[2983] | 92 | int fts_options; /* fts_open options, global flags */
|
---|
[3535] | 93 | int fts_cwd_fd; /* FTS_CWDFD: AT_FDCWD or a virtual CWD file descriptor. */
|
---|
[2983] | 94 | void *fts_clientptr; /* thunk for sort function */
|
---|
| 95 | } FTS;
|
---|
| 96 |
|
---|
| 97 | typedef struct _ftsent {
|
---|
| 98 | struct _ftsent *fts_cycle; /* cycle node */
|
---|
| 99 | struct _ftsent *fts_parent; /* parent directory */
|
---|
| 100 | struct _ftsent *fts_link; /* next file in directory */
|
---|
[2985] | 101 | int64_t fts_number; /* local numeric value */
|
---|
[2983] | 102 | #define fts_bignum fts_number /* XXX non-std, should go away */
|
---|
| 103 | void *fts_pointer; /* local address value */
|
---|
| 104 | char *fts_accpath; /* access path */
|
---|
[2998] | 105 | wchar_t *fts_wcsaccpath; /* NT: UTF-16 access path */
|
---|
[2983] | 106 | char *fts_path; /* root path */
|
---|
[2998] | 107 | wchar_t *fts_wcspath; /* NT: UTF-16 root path */
|
---|
[2983] | 108 | int fts_errno; /* errno for this node */
|
---|
[3004] | 109 | size_t fts_alloc_size; /* internal - size of the allocation for this entry. */
|
---|
[2997] | 110 | fts_fd_t fts_dirfd; /* NT: Handle to the directory (NT_FTS_)INVALID_HANDLE_VALUE if not valid */
|
---|
[2985] | 111 | size_t fts_pathlen; /* strlen(fts_path) */
|
---|
[2998] | 112 | size_t fts_cwcpath; /* NT: length of fts_wcspath. */
|
---|
[2985] | 113 | size_t fts_namelen; /* strlen(fts_name) */
|
---|
[2998] | 114 | size_t fts_cwcname; /* NT: length of fts_wcsname. */
|
---|
[2983] | 115 |
|
---|
[2985] | 116 | fts_ino_t fts_ino; /* inode */
|
---|
| 117 | fts_dev_t fts_dev; /* device */
|
---|
[3004] | 118 | fts_nlink_t fts_nlink; /* link count */
|
---|
[2983] | 119 |
|
---|
| 120 | #define FTS_ROOTPARENTLEVEL -1
|
---|
| 121 | #define FTS_ROOTLEVEL 0
|
---|
| 122 | long fts_level; /* depth (-1 to N) */
|
---|
| 123 |
|
---|
| 124 | #define FTS_D 1 /* preorder directory */
|
---|
| 125 | #define FTS_DC 2 /* directory that causes cycles */
|
---|
| 126 | #define FTS_DEFAULT 3 /* none of the above */
|
---|
| 127 | #define FTS_DNR 4 /* unreadable directory */
|
---|
| 128 | #define FTS_DOT 5 /* dot or dot-dot */
|
---|
| 129 | #define FTS_DP 6 /* postorder directory */
|
---|
| 130 | #define FTS_ERR 7 /* error; errno is set */
|
---|
| 131 | #define FTS_F 8 /* regular file */
|
---|
| 132 | #define FTS_INIT 9 /* initialized only */
|
---|
| 133 | #define FTS_NS 10 /* stat(2) failed */
|
---|
| 134 | #define FTS_NSOK 11 /* no stat(2) requested */
|
---|
| 135 | #define FTS_SL 12 /* symbolic link */
|
---|
| 136 | #define FTS_SLNONE 13 /* symbolic link without target */
|
---|
[3535] | 137 | #define FTS_W 14 /* whiteout object */
|
---|
[2983] | 138 | int fts_info; /* user status for FTSENT structure */
|
---|
| 139 |
|
---|
| 140 | #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
|
---|
| 141 | #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
|
---|
| 142 | #define FTS_ISW 0x04 /* this is a whiteout object */
|
---|
| 143 | unsigned fts_flags; /* private flags for FTSENT structure */
|
---|
| 144 |
|
---|
| 145 | #define FTS_AGAIN 1 /* read node again */
|
---|
| 146 | #define FTS_FOLLOW 2 /* follow symbolic link */
|
---|
| 147 | #define FTS_NOINSTR 3 /* no instructions */
|
---|
| 148 | #define FTS_SKIP 4 /* discard node */
|
---|
| 149 | int fts_instr; /* fts_set() instructions */
|
---|
| 150 |
|
---|
| 151 | struct stat *fts_statp; /* stat(2) information */
|
---|
| 152 | char *fts_name; /* file name */
|
---|
[2998] | 153 | wchar_t *fts_wcsname; /* NT: UTF-16 file name. */
|
---|
[2983] | 154 | FTS *fts_fts; /* back pointer to main FTS */
|
---|
[2985] | 155 | BirdStat_T fts_stat; /* NT: We always got stat info. */
|
---|
[2983] | 156 | } FTSENT;
|
---|
| 157 |
|
---|
| 158 |
|
---|
[2985] | 159 | #ifdef __cplusplus
|
---|
| 160 | extern "C" {
|
---|
| 161 | #endif
|
---|
[2992] | 162 |
|
---|
| 163 | FTSENT *FTSCALL nt_fts_children(FTS *, int);
|
---|
| 164 | int FTSCALL nt_fts_close(FTS *);
|
---|
| 165 | void *FTSCALL nt_fts_get_clientptr(FTS *);
|
---|
[2983] | 166 | #define fts_get_clientptr(fts) ((fts)->fts_clientptr)
|
---|
[2992] | 167 | FTS *FTSCALL nt_fts_get_stream(FTSENT *);
|
---|
[2983] | 168 | #define fts_get_stream(ftsent) ((ftsent)->fts_fts)
|
---|
[2998] | 169 | FTS *FTSCALL nt_fts_open(char * const *, int, int (FTSCALL*)(const FTSENT * const *, const FTSENT * const *));
|
---|
| 170 | FTS *FTSCALL nt_fts_openw(wchar_t * const *, int, int (FTSCALL*)(const FTSENT * const *, const FTSENT * const *));
|
---|
[2992] | 171 | FTSENT *FTSCALL nt_fts_read(FTS *);
|
---|
| 172 | int FTSCALL nt_fts_set(FTS *, FTSENT *, int);
|
---|
| 173 | void FTSCALL nt_fts_set_clientptr(FTS *, void *);
|
---|
| 174 |
|
---|
| 175 | /* API mappings. */
|
---|
| 176 | #define fts_children(a_pFts, a_iInstr) nt_fts_children(a_pFts, a_iInstr)
|
---|
| 177 | #define fts_close(a_pFts) nt_fts_close(a_pFts)
|
---|
| 178 | #define fts_open(a_papszArgs, a_fOptions, a_pfnCompare) nt_fts_open(a_papszArgs, a_fOptions, a_pfnCompare)
|
---|
| 179 | #define fts_read(a_pFts) nt_fts_read(a_pFts)
|
---|
| 180 | #define fts_set(a_pFts, a_pFtsEntry, a_iInstr) nt_fts_set(a_pFts, a_pFtsEntry, a_iInstr)
|
---|
| 181 | #define fts_set_clientptr(a_pFts, a_pvUser) nt_fts_set_clientptr(a_pFts, a_pvUser)
|
---|
| 182 |
|
---|
[2985] | 183 | #ifdef __cplusplus
|
---|
| 184 | }
|
---|
| 185 | #endif
|
---|
[2983] | 186 |
|
---|
[2985] | 187 | #endif /* !INCLUDED_FTS_NT_H */
|
---|
| 188 |
|
---|