tech-userlevel archive

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

Re: sh(1) read: add LINE_MAX safeguard and "-n" option



    Date:        Tue, 24 Sep 2024 12:56:49 +0200
    From:        <tlaronde%kergis.com@localhost>
    Message-ID:  <ZvKa8e8a7FHIFLz6%kergis.com@localhost>

  | The present patch does two things:
  |
  | 1) Set, by default, the maximum of bytes read, in every case, as being
  | LINE_MAX (the maximum number of bytes in a line in a text file);

I am not really in favour of that part, while allowed by the standard,
imposing unnecessary limits, just because they are permitted, is not
really ideal.   Apart from that, the "line" read by read (without -r)
can actually be several (or many) text file lines, if each is ended by
a \ (line continuation).

  | 2) Implement the '-n' option that allows to set explicitely the 
  | maximum number of bytes to read, thus allowing too to bypass deliberately
  | the LINE_MAX value.

Martin suggested that as well.  Your implementation isn't correct
as it is (if the limit is reached, the next character will be discarded,
that's not allowed ... also easy to fix) but before doing anything I
want to check what other shells which implement the option actually
count (particularly  wrt \ sequences, but also the word splitting).
There is no point being needlessly different if that is possible to
avoid.

  | BTW: the usage displayed when a variable name was not given didn't
  | show the "[-d delim]" option.

Sometimes things just get forgotten... ;=)

kre


Home | Main Index | Thread Index | Old Index