uniq truncates lines > 2048 bytes

Scot Hetzel swhetzel at gmail.com
Wed Jan 26 07:27:05 PST 2005


On Wed, 26 Jan 2005 09:10:47 +1100, Tim Robbins <tjr at freebsd.org> wrote:
> This looks good except for failure to check for realloc() returning NULL
> and a few minor style problems. It may be possible to use fgetwln()
> to read lines instead of getwc() + realloc() etc., but this function is
> new and peculiar to FreeBSD.
> 
I tried to use fgetwln in place of the getline sub-routine:

 if ((prevline = fgetwln(ifp, prevbuflen)) == NULL) {
:
}

while ((thisline = fgetwln(ifp, thisbuflen)) != NULL) {
:
}

But what is happening is that both thisline and prevline are being set
to the same pointer location.  I need to change it to:

 if ((thisline = fgetwln(ifp, thisbuflen)) == NULL) {
: /* check error */
}
prevline = strdup(thisline);

while ((thisline = fgetwln(ifp, thisbuflen)) != NULL) {
:
if (comp) {
:
/* place thisline into prevline */
prevline = strdup(thisline);
:
}
:
}

Is their a function to duplicate wchar strings?

Scot


More information about the freebsd-current mailing list