dir.c (67350cb56a69468c118bd4ccf6e361b7ebfa9eb4) dir.c (ef0b253881c9546ff88d3ed8480df7c791b3ddff)
1/* $NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $ */
1/* $NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $ */
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

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

65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

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

65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
73static char rcsid[] = "$NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $";
73static char rcsid[] = "$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $";
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
79#else
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
79#else
80__RCSID("$NetBSD: dir.c,v 1.73 2018/07/12 18:03:31 christos Exp $");
80__RCSID("$NetBSD: dir.c,v 1.74 2020/06/05 18:03:59 sjg Exp $");
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * dir.c --
87 * Directory searching using wildcards and/or normal names...
88 * Used both for source wildcarding in the Makefile and for finding

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

258static char *DirLookupAbs(Path *, const char *, const char *);
259
260
261/*
262 * We use stat(2) a lot, cache the results
263 * mtime and mode are all we care about.
264 */
265struct cache_st {
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * dir.c --
87 * Directory searching using wildcards and/or normal names...
88 * Used both for source wildcarding in the Makefile and for finding

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

258static char *DirLookupAbs(Path *, const char *, const char *);
259
260
261/*
262 * We use stat(2) a lot, cache the results
263 * mtime and mode are all we care about.
264 */
265struct cache_st {
266 time_t mtime;
266 time_t lmtime; /* lstat */
267 time_t mtime; /* stat */
267 mode_t mode;
268};
269
270/* minimize changes below */
271#define CST_LSTAT 1
272#define CST_UPDATE 2
273
274static int

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

282 return -1;
283
284 entry = Hash_FindEntry(htp, pathname);
285
286 if (entry && (flags & CST_UPDATE) == 0) {
287 cst = entry->clientPtr;
288
289 memset(st, 0, sizeof(*st));
268 mode_t mode;
269};
270
271/* minimize changes below */
272#define CST_LSTAT 1
273#define CST_UPDATE 2
274
275static int

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

283 return -1;
284
285 entry = Hash_FindEntry(htp, pathname);
286
287 if (entry && (flags & CST_UPDATE) == 0) {
288 cst = entry->clientPtr;
289
290 memset(st, 0, sizeof(*st));
290 st->st_mtime = cst->mtime;
291 st->st_mode = cst->mode;
291 st->st_mode = cst->mode;
292 if (DEBUG(DIR)) {
293 fprintf(debug_file, "Using cached time %s for %s\n",
294 Targ_FmtTime(st->st_mtime), pathname);
292 st->st_mtime = (flags & CST_LSTAT) ? cst->lmtime : cst->mtime;
293 if (st->st_mtime) {
294 if (DEBUG(DIR)) {
295 fprintf(debug_file, "Using cached time %s for %s\n",
296 Targ_FmtTime(st->st_mtime), pathname);
297 }
298 return 0;
295 }
299 }
296 return 0;
297 }
298
299 rc = (flags & CST_LSTAT) ? lstat(pathname, st) : stat(pathname, st);
300 if (rc == -1)
301 return -1;
302
303 if (st->st_mtime == 0)
304 st->st_mtime = 1; /* avoid confusion with missing file */
305
306 if (!entry)
307 entry = Hash_CreateEntry(htp, pathname, NULL);
300 }
301
302 rc = (flags & CST_LSTAT) ? lstat(pathname, st) : stat(pathname, st);
303 if (rc == -1)
304 return -1;
305
306 if (st->st_mtime == 0)
307 st->st_mtime = 1; /* avoid confusion with missing file */
308
309 if (!entry)
310 entry = Hash_CreateEntry(htp, pathname, NULL);
308 if (!entry->clientPtr)
311 if (!entry->clientPtr) {
309 entry->clientPtr = bmake_malloc(sizeof(*cst));
312 entry->clientPtr = bmake_malloc(sizeof(*cst));
313 memset(entry->clientPtr, 0, sizeof(*cst));
314 }
310 cst = entry->clientPtr;
315 cst = entry->clientPtr;
311 cst->mtime = st->st_mtime;
316 if ((flags & CST_LSTAT)) {
317 cst->lmtime = st->st_mtime;
318 } else {
319 cst->mtime = st->st_mtime;
320 }
312 cst->mode = st->st_mode;
313 if (DEBUG(DIR)) {
314 fprintf(debug_file, " Caching %s for %s\n",
315 Targ_FmtTime(st->st_mtime), pathname);
316 }
317
318 return 0;
319}

--- 1530 unchanged lines hidden ---
321 cst->mode = st->st_mode;
322 if (DEBUG(DIR)) {
323 fprintf(debug_file, " Caching %s for %s\n",
324 Targ_FmtTime(st->st_mtime), pathname);
325 }
326
327 return 0;
328}

--- 1530 unchanged lines hidden ---