delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/10/24/13:43:56

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:message-id:date:from:mime-version:to:subject
:content-type:content-transfer-encoding; q=dns; s=default; b=AHr
7Vy/UFqIFn/PkowNQuJl20tm7DPDAvQEByxjV5kyUa8TqhtyNLmKIQaVlcqtybdx
YTjBc7oW189/9Dn3Arl+UcHpLEyA9/VSNjWXMO1UGUEmTvNgTXd8ovAZpt78mor7
BI0uAH8DeLRFsnxK8cco8CqQK862aYVQR2WmL9/Q=
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:message-id:date:from:mime-version:to:subject
:content-type:content-transfer-encoding; s=default; bh=sWzrfGd9j
dWRZccBkgTU3p6p6pw=; b=SEBXWQPqvbvgf6buSbPRMDoCV1DQ5EZ3ZYg4lXck4
EjrMrX8f8TwSrugt2Id4ELhHXpygTxC4k+8gf9udbw8qqbZs8SXKbpp3+8sYMdZJ
gz2rF1j/rGGynHTp1a7b2j4+dFwQfXwFFhshDOSfEXG56cEWYBwTiwWbmdE9zT6A
10=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.2
X-HELO: mailout07.t-online.de
Message-ID: <52695C49.30505@t-online.de>
Date: Thu, 24 Oct 2013 19:43:37 +0200
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 SeaMonkey/2.19
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: /dev/clipboard: No O_TEXT conversion if write() is used
X-IsSubscribed: yes

fopen("/dev/clipboard", "wt") sets O_TEXT, fprintf() does LF->CRLF 
conversion but write() does not. The latter is IMO a bug.

fopen("/dev/clipboard", "wb") sets both O_TEXT and O_BINARY, fwrite() 
and write() do no conversion. The set_flags() call in 
fhandler_dev_clipboard::open() should possibly clear O_BINARY.

With regular files, everything works as expected.

Testcase:

$ uname -srvm
CYGWIN_NT-6.1-WOW64 1.7.25(0.270/5/3) 2013-08-31 20:39 i686

$ cat testmode.c
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
   const char * name = argv[1], * flags = argv[2];
   FILE * f = fopen(name, flags);
   if (!f) {
     perror(name); return 1;
   }
   int fd = fileno(f), mode = getmode(fd);
   printf("fd=%d, mode=%x%s%s\n", fd, mode,
     (mode & O_BINARY ? " O_BINARY":""),
     (mode & O_TEXT ? " O_TEXT":""));
   fprintf(f, "printf1\nprintf2\n"); fflush(f);
   write(fd, "write1\nwrite2\n", 14);
   fprintf(f, "printf3\nprintf4\n"); fflush(f);
   write(fd, "write3\nwrite4\n", 14);
   fclose(f);
   return 0;
}

$ gcc -o testmode testmode.c

$ ./testmode /dev/clipboard wt ; cat -A /dev/clipboard
fd=3, mode=20000 O_TEXT
printf1^M$
printf2^M$
write1$
write2$
printf3^M$
printf4^M$
write3$
write4$

$ ./testmode /dev/clipboard wb ; cat -A /dev/clipboard
fd=3, mode=30000 O_BINARY O_TEXT
printf1$
printf2$
write1$
write2$
printf3$
printf4$
write3$
write4$

$ ./testmode out wt ; cat -A out
fd=3, mode=20000 O_TEXT
printf1^M$
printf2^M$
write1^M$
...

$ ./testmode out wb ; cat -A out
fd=3, mode=10000 O_BINARY
printf1$
printf2$
write1$
...


This is likely the reason for the following inconsistent behavior:

$ echo test1 >/dev/clipboard ; cat -A /dev/clipboard
test1$

$ /bin/echo test2 >/dev/clipboard ; cat -A /dev/clipboard
test2^M$

$ /bin/echo test3 | cat > /dev/clipboard ; cat -A /dev/clipboard
test3$

$ echo test4 | sed s,x,x, > /dev/clipboard ; cat -A /dev/clipboard
test4^M$


Christian


--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019