From d41df8af857b0df277d109bf12d6070786dee505 Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 15 Nov 2020 09:38:44 +0000 Subject: [PATCH] make(1): clean up getTmpdir Reduce indentation, structure code into paragraphs. --- usr.bin/make/main.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 3035b3009cd6..ecf2139fdf97 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.472 2020/11/15 09:33:50 rillig Exp $ */ +/* $NetBSD: main.c,v 1.473 2020/11/15 09:38:44 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -109,7 +109,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.472 2020/11/15 09:33:50 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.473 2020/11/15 09:38:44 rillig Exp $"); #if defined(MAKE_NATIVE) && !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -2174,21 +2174,19 @@ char * getTmpdir(void) { static char *tmpdir = NULL; + struct stat st; - if (tmpdir == NULL) { - struct stat st; + if (tmpdir != NULL) + return tmpdir; - /* - * Honor $TMPDIR but only if it is valid. - * Ensure it ends with /. - */ - (void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP "}/", VAR_GLOBAL, - VARE_WANTRES, &tmpdir); - /* TODO: handle errors */ - if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) { - free(tmpdir); - tmpdir = bmake_strdup(_PATH_TMP); - } + /* Honor $TMPDIR but only if it is valid. Ensure it ends with '/'. */ + (void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP "}/", + VAR_GLOBAL, VARE_WANTRES, &tmpdir); + /* TODO: handle errors */ + + if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) { + free(tmpdir); + tmpdir = bmake_strdup(_PATH_TMP); } return tmpdir; }