Deleted Added
sdiff udiff text old ( 128946 ) new ( 129052 )
full compact
1/*-
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

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

32 *
33 * $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $
34 */
35
36#if defined(LIBC_SCCS) && !defined(lint)
37static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
38#endif /* LIBC_SCCS and not lint */
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD: head/lib/libc/gen/fts-compat.c 128946 2004-05-05 06:33:00Z kientzle $");
41
42#include "namespace.h"
43#include <sys/types.h>
44#include <sys/param.h>
45#include <sys/stat.h>
46
47#include <dirent.h>
48#include <errno.h>
49#include <fcntl.h>
50#include <fts.h>
51#include <stdlib.h>
52#include <string.h>
53#include <unistd.h>

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

58static void fts_lfree(FTSENT *);
59static void fts_load(FTS *, FTSENT *);
60static size_t fts_maxarglen(char * const *);
61static void fts_padjust(FTS *, FTSENT *);
62static int fts_palloc(FTS *, size_t);
63static FTSENT *fts_sort(FTS *, FTSENT *, int);
64static u_short fts_stat(FTS *, FTSENT *, int);
65static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
66
67#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
68
69#define CLR(opt) (sp->fts_options &= ~(opt))
70#define ISSET(opt) (sp->fts_options & (opt))
71#define SET(opt) (sp->fts_options |= (opt))
72
73#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
74
75/* fts_build flags */
76#define BCHILD 1 /* fts_children */
77#define BNAMES 2 /* fts_children, names only */
78#define BREAD 3 /* fts_read */
79
80FTS *
81fts_open(argv, options, compar)
82 char * const *argv;
83 int options;
84 int (*compar)(const FTSENT * const *, const FTSENT * const *);
85{
86 FTS *sp;
87 FTSENT *p, *root;
88 int nitems;
89 FTSENT *parent, *tmp;
90 int len;
91
92 /* Options check. */
93 if (options & ~FTS_OPTIONMASK) {
94 errno = EINVAL;
95 return (NULL);
96 }
97
98 /* Allocate/initialize the stream */
99 if ((sp = malloc(sizeof(FTS))) == NULL)
100 return (NULL);
101 memset(sp, 0, sizeof(FTS));
102 sp->fts_compar = compar;
103 sp->fts_options = options;
104
105 /* Shush, GCC. */
106 tmp = NULL;
107
108 /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
109 if (ISSET(FTS_LOGICAL))
110 SET(FTS_NOCHDIR);
111

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

632 * directory if we're cheating on stat calls, 0 if we're not doing
633 * any stat calls at all, -1 if we're doing stats on everything.
634 */
635 if (type == BNAMES) {
636 nlinks = 0;
637 /* Be quiet about nostat, GCC. */
638 nostat = 0;
639 } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
640 nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
641 nostat = 1;
642 } else {
643 nlinks = -1;
644 nostat = 0;
645 }
646
647#ifdef notdef
648 (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);

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

1149 ret = fchdir(newfd);
1150bail:
1151 oerrno = errno;
1152 if (fd < 0)
1153 (void)_close(newfd);
1154 errno = oerrno;
1155 return (ret);
1156}