[syslinux] [PATCH 4/4] extlinux: simplification by removing one label

Celelibi celelibi at gmail.com
Tue Nov 17 22:33:28 PST 2015


2015-11-13 21:19 UTC+01:00, Nicolas Cornu via Syslinux <syslinux at zytor.com>:
> Now that xfs_install_file is simplified by using new helpers, we can
> remove use of label/goto for clarity.
>
> Signed-off-by: Nicolas Cornu <nicolac76 at yahoo.fr>
> ---
>  extlinux/main.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/extlinux/main.c b/extlinux/main.c
> index 43c1a31..8b97a71 100644
> --- a/extlinux/main.c
> +++ b/extlinux/main.c
> @@ -735,28 +735,22 @@ static int xfs_install_file(const char *path, int
> devfd, struct stat *rst)
>      dirfd = open(path, O_RDONLY | O_DIRECTORY);
>      if (dirfd < 0) {
>  	perror(path);
> -	goto bail;
> +	return 1;
>      }
>
> -    if (ext_install_ldlinux_sys(devfd, path, rst))
> -	goto bail;
> +    if (ext_install_ldlinux_sys(devfd, path, rst)) {
> +	close(dirfd);
> +	return 1;
> +    }
>
>      close(dirfd);
>
> -    dirfd = -1;
> -
>      if (ext_install_ldlinux_c32(path))
> -	goto bail;
> +	return 1;
>
>      sync();
>
>      return 0;
> -
> -bail:
> -    if (dirfd >= 0)
> -	close(dirfd);
> -
> -    return 1;
>  }
>
>  /*
> --
> 2.6.2

I would just note that gotos are often used in C (at least in Linux)
as a a simulation of exceptions. The label is at the end of the
function doing some clean up and returning an error code. That's a
common pattern.

That being said, as your patch shorten the code length, I guess we can
say it's better.

Celelibi


More information about the Syslinux mailing list