X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type:date:from:to:subject :message-id; q=dns; s=default; b=fE6lMqs2RaVBOur6hKS2vdAPyOPeaUn +ZWs338bwMhmKPhrXjPIG13KDyVCgUbX96KeiPWqmcEEFJPUxMcEzndWXQMOO40u hdWNQSNrU3aFdD4AItFgV/ATzBG9QDN6CIhlUFTiXussnNJSlyfqitWzKwlxsNDY B8CWYct5T+Dc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type:date:from:to:subject :message-id; s=default; bh=YxqSaXrCtkAFaW1aV0ARVM2Z//4=; b=S9ZQW 0tuNKzbmhAW3va53EU8QwVqwzp8E/ivlGGyn7WXQksCRUVuSVqVgYn1xEEkMUsu2 qM8OIz8o9zsC9CFwRk21+kuULdlyDETaQCG9wYUciFpUid7N0eV6qokpQgpzcDmA mDwJdgrFOegbeeW+868gX7SJS5zoJY0Vm+MQjg= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=BAYES_20,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=D*@, steps, UD:cygwin.com, cygwincom X-HELO: lb1-smtp-cloud8.xs4all.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_32a5c9107b957f67274152ccd79cd4a9" Date: Sun, 16 Dec 2018 17:31:32 +0100 From: Houder To: cygwin AT cygwin DOT com Subject: /dev/fd/N not synonymous with file descriptor N; it is on Linux Message-ID: <0f030e809f063f5a5e64ff7a7a0c3227@xs4all.nl> X-Sender: houder AT xs4all DOT nl User-Agent: XS4ALL Webmail X-IsSubscribed: yes --=_32a5c9107b957f67274152ccd79cd4a9 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed L.S., /dev/fd/N not synonymous with file descriptor N; it is on Linux 64-@@ cat /dev/fd/0 <<\EOF > Hi > EOF cat: /dev/fd/0: No such file or directory fails on Cygwin; not on Linux. Also see: https://cygwin.com/ml/cygwin/2018-12/msg00028.html ( Bash heredoc on FD 3 ) Based on the output of strace on Linux, I composed an STC, that duplicates the steps taken by bash (and cat). This STC succeeds on Linux, but fails on Cygwin. What does the STC do: - it creates a (temporary) file in the same way that bash does - the file is written to, the file descriptor is closed and the file unlinked - however, before the file is unlinked, it is opened a second time, like bash would do Next - the file /dev/fd/N is opened, where N is the file descriptor that has been left open; this is what the "cat command" would do. The "cat command" on Linux succeeds; it fails on Cygwin. Regards, Henri STC attached (hopefully) ===== --=_32a5c9107b957f67274152ccd79cd4a9 Content-Transfer-Encoding: base64 Content-Type: text/x-c; name=stc.c Content-Disposition: attachment; filename=stc.c; size=3256 Ly8gZ2NjIC1XYWxsIC1vIHN0YyBzdGMuYwoKI2luY2x1ZGUgPHN0ZGlvLmg+ CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgojaW5j bHVkZSA8c3RyaW5nLmg+IC8vIHN0cmVycm9yKCkKI2luY2x1ZGUgPGVycm5v Lmg+CiNpbmNsdWRlIDxmY250bC5oPgoKLyoKIExQSSwgNS4xMSBUaGUgL2Rl di9mZCBEaXJlY3RvcnkgKExpbnV4IFByb2dyYW1taW5nIEludGVyZmFjZSwg TWljaGFlbCBLZXJyaXNrKQogIkZvciBlYWNoIHByb2Nlc3MsIHRoZSBrZXJu ZWwgcHJvdmlkZXMgdGhlIHNwZWNpYWwgdmlydHVhbCBkaXJlY3RvcnkgL2Rl di9mZC4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vLyB0aGUgb3BlbiBm aWxlIGRlc2NyaXB0b3Igb2YgdGhlIHByb2Nlc3MgLi4uCiAgICAgICAgZXJy bm8gPSAwOwogICAgICAgIGlmIChyZWFkKGZkMiwgYnVmLCBzaXplb2YoYnVm KSApID09IC0xKSBlcnJFeGl0KCJyZWFkZmQyIik7CiAgICAgICAgcHJpbnRm KCJidWYgPSAlcyIsIGJ1Zik7CiAgICAgICAgaWYgKGNsb3NlKGZkMikgPT0g LTEpIHByaW50ZigiY2xvc2VmZDIgZmFpbGVkXG4iKTsKICAgICAgICBleGl0 KEVYSVRfRkFJTFVSRSk7CiNlbmRpZgogICAgfQoKICAgIGNoYXIgYnVmWzE2 XSA9IHsgMCB9OwogICAgZXJybm8gPSAwOwogICAgaWYgKHJlYWQoZmQzLCBi dWYsIHNpemVvZihidWYpICkgPT0gLTEpIGVyckV4aXQoInJlYWRmZDMiKTsK ICAgIHByaW50ZigiYnVmID0gJXMiLCBidWYpOwoKICAgIGlmIChjbG9zZShm ZDMpID09IC0xKSBwcmludGYoImNsb3NlZmQzIGZhaWxlZFxuIik7CiAgICBp ZiAoY2xvc2UoZmQyKSA9PSAtMSkgcHJpbnRmKCJjbG9zZWZkMiBmYWlsZWRc biIpOwp9CgovLz09PT09Cg== --=_32a5c9107b957f67274152ccd79cd4a9 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --=_32a5c9107b957f67274152ccd79cd4a9--