1#include "config.h" 2 3#if HAVE_FTS 4 5int dummy; 6 7#else 8 |
9/* $Id: compat_fts.c,v 1.8 2015/02/07 07:53:01 schwarze Exp $ */ 10/* $OpenBSD: fts.c,v 1.50 2015/01/16 16:48:51 deraadt Exp $ */ |
11 12/*- 13 * Copyright (c) 1990, 1993, 1994 14 * The Regents of the University of California. All rights reserved. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: --- 14 unchanged lines hidden (view full) --- 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 */ 40 |
41#include <sys/stat.h> 42#include <sys/types.h> 43 44#include <dirent.h> 45#include <errno.h> 46#include <fcntl.h> 47#include <limits.h> 48#include <stdlib.h> 49#include <string.h> 50#include <unistd.h> 51#include "compat_fts.h" 52 |
53#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) 54 |
55static FTSENT *fts_alloc(FTS *, const char *, size_t); 56static FTSENT *fts_build(FTS *); 57static void fts_lfree(FTSENT *); 58static void fts_load(FTS *, FTSENT *); 59static size_t fts_maxarglen(char * const *); 60static void fts_padjust(FTS *, FTSENT *); 61static int fts_palloc(FTS *, size_t); 62static unsigned short fts_stat(FTS *, FTSENT *); 63static int fts_safe_changedir(FTS *, FTSENT *, int, const char *); 64 65#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) |
66#ifndef O_DIRECTORY 67#define O_DIRECTORY 0 68#endif |
69#ifndef O_CLOEXEC 70#define O_CLOEXEC 0 71#endif |
72 73#define CLR(opt) (sp->fts_options &= ~(opt)) 74#define ISSET(opt) (sp->fts_options & (opt)) 75#define SET(opt) (sp->fts_options |= (opt)) 76 77#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 78 79FTS * --- 15 unchanged lines hidden (view full) --- 95 if ((sp = calloc(1, sizeof(FTS))) == NULL) 96 return (NULL); 97 sp->fts_options = options; 98 99 /* 100 * Start out with 1K of path space, and enough, in any case, 101 * to hold the user's paths. 102 */ |
103 if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX))) |
104 goto mem1; 105 106 /* Allocate/initialize root's parent. */ 107 if ((parent = fts_alloc(sp, "", 0)) == NULL) 108 goto mem2; 109 parent->fts_level = FTS_ROOTPARENTLEVEL; 110 111 /* Allocate/initialize root(s). */ --- 697 unchanged lines hidden --- |