From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg0-f51.google.com ([74.125.83.51]) by ur; Mon Mar 27 21:42:54 EDT 2017 Received: by mail-pg0-f51.google.com with SMTP id n5so49473946pgh.0 for <9front@9front.org>; Mon, 27 Mar 2017 18:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:subject:message-id:date:to :mime-version; bh=Js2kABNDGAGozaxHyJ032bqTGg33cLY1AqE9z1F1JOY=; b=m4qjp5FQRX3KVoGeGsc9EIGtCb6KTQhGF25DqkwQw9D4ZUX7HdGJzEQA/l0otlaex0 CMgn8nUjc3iZhaLphrgmjHni58LASp9A+DdcFzoZqhUfu3u7xwF2lzSWX1twTr10Z2/x pwl3+1IxGbTk5vqyGOHKw4A/nn5iUjRtKBMoS0JLFeKWU8LpOVuoL2+6tVOmcbcF2Q0M Mm67fe+fzE4ATIZPhsT9dc+nQKxFl0SQhtXjtwQJQqZByJ7uaq27DAnRvtnmfA1rHPsF 0EG6UOsP/PvesW/RwvQKSE3Sy+q4LxisyQvGiQJjJIKIiQIzffsLT//9vfsLyo2WXndh uESg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:subject :message-id:date:to:mime-version; bh=Js2kABNDGAGozaxHyJ032bqTGg33cLY1AqE9z1F1JOY=; b=WejY2xTvEOyVoOkgHjzOintqfIeANCNFabiKMzCU1u6CvmxWtjMkLAx7EBv+kQkDVv iD0nBcxeU/dhvpPRFE/gybwjyFzBYR7RlYS5TsgJHf2zGrb1XShICm8O4mxZbj63i2ol cDLd7+KqgsDaFEW78vKFiw729R6twne0GmJxfk+A6L+Ui3vp3S0DQbZ+j+fGOIHxLKME OOiVtheq1OjLIbXUqq7hX27VyodOKGFvAtrPeCrj0iSXG3VZ1G/1JwIvF8PPFWACtUVZ cZf0Zdc7e9M08e2UYPZlD1zGnXRfo8DrTiFGn4B/iLkkZY8mdjb13my190r7xiHch2zj oJdg== X-Gm-Message-State: AFeK/H3J51aUhTXR7axD5pOFM8LW64OLXLKTLOhx+klsH0TXLZ0Flrv46vDF8KWMdwGKxQ== X-Received: by 10.99.157.6 with SMTP id i6mr27705276pgd.87.1490665371124; Mon, 27 Mar 2017 18:42:51 -0700 (PDT) Return-Path: Received: from [192.168.0.249] (115-36-90-13.chubu1.commufa.jp. [115.36.90.13]) by smtp.gmail.com with ESMTPSA id y64sm3486884pfy.3.2017.03.27.18.42.49 for <9front@9front.org> (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Mar 2017 18:42:50 -0700 (PDT) From: arisawa Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: pipe: bug or feature? Message-Id: Date: Tue, 28 Mar 2017 10:42:47 +0900 To: 9front@9front.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) X-Mailer: Apple Mail (2.2104) List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: metadata-aware enhancement-scale shader element control Hello, I was playing with an experimental program on pipe and met with a = problem which I don=E2=80=99t understand. the program reads a file and writes it back to one end of pipe and then = reads it from another end of pipe. the buffer for writing pipe is named buf0, and for reading pipe is named = buf. and I found the program does not finish unless sizeof(buf) > = sizeof(buf0). is this a bug or a feature of pipe? Kenji Arisawa =3D=3D=3D BEGIN a.c =3D=3D=3D #include #include char *argv0; void usage(void) { fprint(2,"usage: %s file\n",argv0); exits("usage"); } void main(int argc, char *argv[]) { int fd,pfd[2]; char buf[256]; char buf0[256]; /* need to be sizeof(buf) > sizeof(buf0) * but this condition is very curious to me */ int n; char *file; argv0 =3D argv[0]; argc--;argv++; USED(argc); if(argv[0] =3D=3D nil) usage(); file =3D argv[0]; fd =3D open(file,OREAD); if(fd < 0) sysfatal("no such file"); if(pipe(pfd) < 0) sysfatal("pipe error"); print("pfd: %d %d\n",pfd[0],pfd[1]); while((n =3D read(fd,buf0,sizeof(buf0))) > 0){ print("read: %d %s\n",n,file); n =3D write(pfd[1],buf0,n); print("write: %d\n",n); } close(pfd[1]); while((n =3D read(pfd[0],buf,sizeof(buf))) > 0){ buf[n] =3D 0; print("%d %s\n",n,buf); } print("%d\n",n); =09 exits(nil); } =3D=3D=3D END a.c =3D=3D=3D