From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13492 Path: news.gmane.org!.POSTED!not-for-mail From: Xan Phung Newsgroups: gmane.linux.lib.musl.general Subject: Re: stdio glitch & questions Date: Sat, 1 Dec 2018 19:02:02 +1100 Message-ID: References: <20181130160951.GS23599@brightrain.aerifal.cx> <20181201000229.GT23599@brightrain.aerifal.cx> <20181201031736.GU23599@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ec73c8057bf15684" X-Trace: blaine.gmane.org 1543651248 17231 195.159.176.226 (1 Dec 2018 08:00:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 1 Dec 2018 08:00:48 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-13508-gllmg-musl=m.gmane.org@lists.openwall.com Sat Dec 01 09:00:44 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gT0Ci-0004OH-0N for gllmg-musl@m.gmane.org; Sat, 01 Dec 2018 09:00:44 +0100 Original-Received: (qmail 24434 invoked by uid 550); 1 Dec 2018 08:02:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24413 invoked from network); 1 Dec 2018 08:02:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=U+B2RGgKPX/yDJs5y/3M3ZX8PjE06FN2Xag1a3Dg2rE=; b=CfIQ7c1uH/rNTvfjkmCefJsGGw1J6kmYRcG4t3L+xFhM/33ki2AAs44zvTOdX7eDQw wLUE6nJTQ+KbVT2y9nc1Tp5TcQa5hTRRhx1S7uc4LhplA8gIzrecY5yLES4lbyfxzW+t u5aj+4pi7voIlsnjNGfsDT1OOfUTULvNwIH/tvomBzKXv7EnvmsUIy1cKV/yuiiottZB PKNmt4q2kNV3wpL3945jyJTr7Gyc+EFC49z+Dyt9gFa7dfSa6sfVt5su6qM4T3rDOZmI o0dhTIVt9MaBzBZO371dzuThilKsJpHBTCI88b777ST/i2ngLIfwwOZW1G91vWqxHlfe zJ2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=U+B2RGgKPX/yDJs5y/3M3ZX8PjE06FN2Xag1a3Dg2rE=; b=BAo7M2vnnYrFnSo9khFO0B+TIEFMVIT0am9nzCg0a7fipZ0BJNPoQCOk87f9bwRbja yM201CybUBKMEc4BGaplKPI4dggt70QV1+PCDBSuNtz1B+u09DihybUI5HlJr5Wgffo2 /if5e3ZDcoVnzhvTSo0rPHuEGp65DZb6/+05Nr/XVk/lO3qf2jDJRK452wxRbmea9tQW 0N1pNNo9vtZTPTn5eJYj02Ml4rKS8O9V3B1zTkV6bKXO6M/ER1b5/gpf8JEIblmn1hgE aBSiO7WJ48JAqa/sKiN/57BaoDWz+qLsrMEp67zuzrVu3/1tKMRSb8JtB8YRXsBjIpqM zITw== X-Gm-Message-State: AA+aEWZXoDXhge+0KTPyxqCxfRjQe8BDEe6GRQCpI/CifbJN3t6wHilz nXz08LdtH8Dr9gLKMcM+wATwD6pASPa8HS5gUZDYBcXh X-Google-Smtp-Source: AFSGD/W8IBFEJpUayQylz6unYN5O5jcT8N2UreonLfbp6ek/6gw/TlAHfrz4CY82wUcZFf5JLymZ6uM8Ayc2LyagceE= X-Received: by 2002:ab0:251:: with SMTP id 75mr3903788uas.39.1543651359223; Sat, 01 Dec 2018 00:02:39 -0800 (PST) In-Reply-To: <20181201031736.GU23599@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13492 Archived-At: --000000000000ec73c8057bf15684 Content-Type: text/plain; charset="UTF-8" > > So anyway, I think there are probably some good reasons to do the > merging in __fwritex rather than in the __stdio_write backend. But it > should be a lot simpler than what you initially proposed. > > Rich > Thanks for your feedback! In interest of keeping the proposal as simple as possible, I've gone with just one extra line of code (see below). It simply does copying for i <= 8. It works on my initial testing and I'm getting zero lengths in the 2nd writev iovec (as expected), but I'll test it more in coming week. size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) { size_t i=0; if (!f->wend && __towrite(f)) return 0; if (l > f->wend - f->wpos) return f->write(f, s, l); if (f->lbf >= 0) { /* Match /^(.*\n|)/ */ for (i=l; i && s[i-1] != '\n'; i--); if (i) { *if (i <= 8) for (; i; i--, l--) *(f->wpos)++ = *s++;* size_t n = f->write(f, s, i); if (*!f->wpos ||* n < i) return n; l -= i; s += i; } } memcpy(f->wpos, s, l); f->wpos += l; return l+i; } --000000000000ec73c8057bf15684 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable




So anyway, I think there are probably some good reasons to do the
merging in __fwritex rather than in the __stdio_write backend. But it
should be a lot simpler than what you initially proposed.

Rich

Thanks for your feedback!=C2=A0 In= interest of keeping the proposal as simple as possible, I've gone with= just one extra line of code (see below).=C2=A0 It simply does copying for= =C2=A0 i <=3D 8.

It works on my initial testing= and I'm getting zero lengths in the 2nd writev iovec (as expected), bu= t I'll test it more in coming week.

size_t __fwritex(const unsigned char *= restrict s, size_t l, FILE *restrict f)

{

size_t= i=3D0;


i= f (!f->w= end && __towrite(f)) return 0;


if (l > f->wend - f->wpos) return f->write(f, s, l);


=

if (f->lbf >=3D 0) {

/* Match /^(.*\n|)/ */=

for (i=3Dl; i && s[i-1] !=3D '\n'; i--);

if (i) {

if (i <=3D 8) for<= /span> (; i; i--, l--) *(f->wpos)++ =3D *s++;

size_t n =3D f->= ;write(f, s= , i);

if = (!f->wpos || n < i) return n= ;

l -=3D i;

= s += =3D i;

}

}<= /p>


memcpy= (f->wpos= , s, l);

f->wpos +=3D l;

retu= rn l+i;

}

--000000000000ec73c8057bf15684--