From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 46B933857C53 for ; Mon, 6 Jul 2020 13:47:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 46B933857C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.193] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 825031E793; Mon, 6 Jul 2020 09:47:54 -0400 (EDT) Subject: Re: [PATCH v2 1/7] Introduce read_entire_file To: Tom Tromey , gdb-patches@sourceware.org References: <20200623132006.15863-1-tom@tromey.com> <20200623132006.15863-2-tom@tromey.com> From: Simon Marchi Message-ID: <39e94988-64f5-0658-7b69-77a0d538809f@simark.ca> Date: Mon, 6 Jul 2020 09:47:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200623132006.15863-2-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jul 2020 13:47:56 -0000 On 2020-06-23 9:20 a.m., Tom Tromey wrote: > +std::string > +read_entire_file (const char *name, int fd, time_t *mtime) > +{ > + struct stat st; > + if (fstat (fd, &st) < 0) > + perror_with_name (name); > + size_t len = st.st_size; > + > + std::string lines; > + lines.resize (len); > + char *addr = &lines[0]; > + > + while (len > 0) > + { > + int val = read (fd, addr, len); Should we handle EINTR here? > + if (val < 0) > + perror_with_name (name); > + if (val == 0) > + break; > + len -= val; > + addr += val; > + } Would you mind adding newlines around the `if` statements? Maybe it's just me, but I find it really more difficult to follow the code when it's all packed. I would mean something like: int val = read (fd, addr, len); if (val < 0) perror_with_name (name); if (val == 0) break; len -= val; addr += val; Like this, my mind is more easily capable of seeing the logical steps. Simon