Deleted Added
full compact
compat_fts.c (276219) compat_fts.c (279527)
1#include "config.h"
2
3#if HAVE_FTS
4
5int dummy;
6
7#else
8
1#include "config.h"
2
3#if HAVE_FTS
4
5int dummy;
6
7#else
8
9/* $Id: compat_fts.c,v 1.6 2014/12/11 18:20:07 schwarze Exp $ */
10/* $OpenBSD: fts.c,v 1.49 2014/11/23 00:14:22 guenther Exp $ */
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
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/param.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44
45#include <dirent.h>
46#include <errno.h>
47#include <fcntl.h>
48#include <limits.h>
49#include <stdlib.h>
50#include <string.h>
51#include <unistd.h>
52#include "compat_fts.h"
53
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
54static FTSENT *fts_alloc(FTS *, const char *, size_t);
55static FTSENT *fts_build(FTS *);
56static void fts_lfree(FTSENT *);
57static void fts_load(FTS *, FTSENT *);
58static size_t fts_maxarglen(char * const *);
59static void fts_padjust(FTS *, FTSENT *);
60static int fts_palloc(FTS *, size_t);
61static unsigned short fts_stat(FTS *, FTSENT *);
62static int fts_safe_changedir(FTS *, FTSENT *, int, const char *);
63
64#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
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])))
65#define MAX(a,b) (((a)>(b))?(a):(b))
66#ifndef O_DIRECTORY
67#define O_DIRECTORY 0
68#endif
66#ifndef O_DIRECTORY
67#define O_DIRECTORY 0
68#endif
69#ifndef O_CLOEXEC
70#define O_CLOEXEC 0
71#endif
69
70#define CLR(opt) (sp->fts_options &= ~(opt))
71#define ISSET(opt) (sp->fts_options & (opt))
72#define SET(opt) (sp->fts_options |= (opt))
73
74#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
75
76FTS *

--- 15 unchanged lines hidden (view full) ---

92 if ((sp = calloc(1, sizeof(FTS))) == NULL)
93 return (NULL);
94 sp->fts_options = options;
95
96 /*
97 * Start out with 1K of path space, and enough, in any case,
98 * to hold the user's paths.
99 */
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 */
100 if (fts_palloc(sp, MAX(fts_maxarglen(argv), PATH_MAX)))
103 if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX)))
101 goto mem1;
102
103 /* Allocate/initialize root's parent. */
104 if ((parent = fts_alloc(sp, "", 0)) == NULL)
105 goto mem2;
106 parent->fts_level = FTS_ROOTPARENTLEVEL;
107
108 /* Allocate/initialize root(s). */

--- 697 unchanged lines hidden ---
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 ---