bug-gnu-libiconv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnu-libiconv] Add -i inplace option for iconv.


From: Bruno Haible
Subject: Re: [bug-gnu-libiconv] Add -i inplace option for iconv.
Date: Tue, 24 Jul 2018 02:11:42 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-130-generic; KDE/5.18.0; x86_64; ; )

Hi,

> I often convert my old text files encoded in iso-8859-1 to utf-8, but
> iconv can not do it inplace. So I created a patch that adds -i option for 
> iconv
> that allows to convert files "inplace".
> 
> Please see the attached patch.

The patch is technically nearly right; the only problematic points are:
  - missing error checking of the fclose(outfile) call,
  - refusal to handle non-regular files (such as symlinks),
  - use of <libgen.h> - better use the corresponding functions from gnulib.

The major problem, however, is:

  - It takes about 60 lines of code to implement something that is better
    done in 1 line of shell script. Needless added complexity. Violates
    the Unix philosophy.
      mv "${f}" "${f}~" && iconv ... < "${f}~" > "${f}" && rm -f "${f}~"

Why is it _better_ done in a shell script?

  - Often when using iconv, the user should prepare a backup of the old
    contents.

  - The way to handle symlinks is specific to the user's environment
    (e.g. they don't want to convert the same file twice).

  - The way to handle the timestamp (modification time) is specific to the
    user's environment.

So, these issues need to be decided by the user. This can be done in a
better way in a shell script.

> I have a question regarding the environmental deps of iconv. Is using
> fstat(), rename(), remove(), mkstemp() allowed?

Yes, these are POSIX functions. Gnulib modules can be used for those that
are not fully portable.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]