From: Andreas Fenkart Date: Fri, 11 Mar 2016 09:39:38 +0100 Subject: [U-Boot] [PATCH 4/6] tools: env: fw_parse_script: simplify removal of newline/carriage return In-Reply-To: <1457685580-28276-1-git-send-email-andreas.fenkart@digitalstrom.com> References: <1457685580-28276-1-git-send-email-andreas.fenkart@digitalstrom.com> Message-ID: <1457685580-28276-5-git-send-email-andreas.fenkart@digitalstrom.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de fgets returns when the first '\n' is found Signed-off-by: Andreas Fenkart --- tools/env/fw_env.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 60574f2..5c7505c 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -566,14 +566,12 @@ int fw_parse_script(char *fname) } /* Drop ending line feed / carriage return */ - while (len > 0 && (dump[len - 1] == '\n' || - dump[len - 1] == '\r')) { - dump[len - 1] = '\0'; - len--; - } + dump[--len] = '\0'; + if (len && dump[len - 1] == '\r') + dump[--len] = '\0'; /* Skip comment or empty lines */ - if ((len == 0) || dump[0] == '#') + if (len == 0 || dump[0] == '#') continue; /* -- 2.7.0