From owner-freebsd-hackers@freebsd.org Mon Jan 8 18:13:23 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 40903E7C307 for ; Mon, 8 Jan 2018 18:13:23 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D9CA66AC8B for ; Mon, 8 Jan 2018 18:13:22 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-io0-f175.google.com with SMTP id 14so15587047iou.2 for ; Mon, 08 Jan 2018 10:13:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=httyc6stZQI6+Xn/sH48vwI+PZGfPwB4Uw2EPv2FEJM=; b=qavVpeSoB2whUif1POLedPY0EfRWzCmZ4dq4rjltO2bnHDqsuevi22r1kiQuRsIOtE 7G73V2KsFUGaOxr/RFftWYFfqt8U1UnCQhGibZ/0Vs92tsacLJApRcPRpKY1lUhhZouG KxInJ0lDdxowXwl1AoBAPnRM9mdgX4DRbEjhtZ9OZy8yw1BNSEU1ecxgjVZ22YUBG+ac V8Ol796umhXqT3faYplKXK3M930Knv+4mBVGRb6bwj32gKlCKXMVuP7+gqnA+9LMmdBK kSLGEgVYZCUgama89ybN43Uh9iahk7pDgrvc1kdAQprEGFJB8anyYzV2KzhL0ifJwrlo tVZg== X-Gm-Message-State: AKGB3mL7pspxo6j73III4K/Leui/TpYpDkFCzkwqT30t4BD2iS1M3Ow+ aTQStgS5HGxr+xoDd1dtJokVGEjZ X-Google-Smtp-Source: ACJfBosgkdbK8jbq5Etgrsrldw+Ymx2ypUojaLA3WtthUS8VKjAAA5sz7AgzPcLebGcsbPN53GVQXQ== X-Received: by 10.36.7.133 with SMTP id f127mr13149640itf.101.1515435201326; Mon, 08 Jan 2018 10:13:21 -0800 (PST) Received: from mail-io0-f176.google.com (mail-io0-f176.google.com. [209.85.223.176]) by smtp.gmail.com with ESMTPSA id o200sm7117754itg.10.2018.01.08.10.13.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 10:13:20 -0800 (PST) Received: by mail-io0-f176.google.com with SMTP id k18so15585893ioc.11 for ; Mon, 08 Jan 2018 10:13:20 -0800 (PST) X-Received: by 10.36.47.207 with SMTP id j198mr12398830itj.119.1515435200292; Mon, 08 Jan 2018 10:13:20 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.2.15.193 with HTTP; Mon, 8 Jan 2018 10:13:19 -0800 (PST) In-Reply-To: References: <201801081655.w08GtO3D022568@pdx.rh.CN85.dnsmgr.net> From: Conrad Meyer Date: Mon, 8 Jan 2018 10:13:19 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? To: Andrew Duane Cc: Freebsd hackers list Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2018 18:13:24 -0000 On Mon, Jan 8, 2018 at 10:05 AM, Andrew Duane wrote: > Of course, my OCD will kick in and say this would need to be something like: > > #ifdef DEBUG_CLOSE > #define close(f) do {if (close(f) < 0) assert(errno != EBADF); } while (0) > #endif > > Have to watch those macro replacements like "if (need_to_close) close(f);". And the close succeeding :-) Of course, this has turned into nerd sniping. But I'll take my turn. Better to use the GCC "statement expression" extension so that the return value of "close()" can still be used by callers naive to the macro. #define close(f) ({ int __ret; __ret = (close)(f); if (__ret < 0) assert(errno != EBADF); __ret; }) Best, Conrad