tech-userlevel archive

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

Re: printf(1), sh(1), POSIX.2 and octal escape sequences



    Date:        Fri, 30 Jun 2023 17:51:13 +0200
    From:        tlaronde%polynum.com@localhost
    Message-ID:  <ZJ758XMIF+YahMqM%polynum.com@localhost>

  | So what is established behavior in this case

It depends upon the usage.   But if you're processing escapes, you
need to also process \\ to mean a literal '\' of course, and once
you have that if the user wants to pass the string \000 to some
application, they can simply write it as \\000 -- there's no need
to assume that \000 as input must have been meant to be \000 as
output that as inserting a literal '\0' is stupid.

As to what to actually do if someone does write \000 (or \0 with
1, 2 or 3 0's) that's kind of up to you.   You can do what the user
said, insert a '\0', and by so doing terminate the input at that
point, or you can simply throw it away, inserting nothing for that
sequence, or generate an error if you want.   Only someone idiotic
enough to actually write \000 in their config file is going to notice.

  | ---and, BTW, most utilities
  | ignore errors with octal sequences (printf(1) for example).

Historic practice, it is just what always has been done.

kre



Home | Main Index | Thread Index | Old Index