Changeset 3261


Ignore:
Timestamp:
May 1, 2007, 4:25:11 PM (18 years ago)
Author:
bird
Message:

Fixed an issue with lseek and \r\n -> \n translation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/essentials/app-shells/bash/lib/sh/zread.c

    r3231 r3261  
    9898  if (lind == lused || lused == 0)
    9999    {
     100#ifdef __OS2__
     101      off_t end, start = lseek (fd, 0, SEEK_CUR);
     102#endif
    100103      nr = zread (fd, lbuf, sizeof (lbuf));
    101104      lind = 0;
     
    105108          return nr;
    106109        }
     110#ifdef __OS2__
     111      /* \r\n -> \n translation screws us down in zsyncfd, so,
     112         we have to check if translation took place and wind back
     113         to right before the first one. New line characters are
     114         read one by one. */
     115      if (start >= 0
     116       && (end = lseek (fd, 0, SEEK_CUR)) > 0
     117       && nr != end - start)
     118        {
     119          if (lbuf[0] == '\n')
     120            {
     121              if (lseek (fd, start, SEEK_SET) >= 0)
     122                {
     123                  nr = zread (fd, lbuf, 1);
     124                  lind = 0;
     125                  if (nr <= 0)
     126                    {
     127                      lused = 0;
     128                      return nr;
     129                    }
     130                }
     131            }
     132          else
     133            {
     134              char *nl = memchr (&lbuf[0], '\n', nr);
     135              if (nl != NULL
     136               && lseek (fd, start + (nl - &lbuf[0]), SEEK_SET) >= 0)
     137                  nr = nl - &lbuf[0];
     138            }
     139        }
     140#endif
    107141      lused = nr;
    108142    }
Note: See TracChangeset for help on using the changeset viewer.