public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Multiple fopens fails with permission denied
@ 2000-03-16  2:31 Tomas Pihl
  2000-03-16  8:45 ` Chris Faylor
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Pihl @ 2000-03-16  2:31 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

I've installed B20.1 (full.exe) on a NT4.0 SP6 machine. When I try
running the below included program I get:

bash-2.02$ ./a.exe
Couldn't open '/dev/com1' for input
open: Permission denied

It doesn't matter in which order I make the calls - fopen() always fail
on the second fopen. Any ideas?

int main()
{
   FILE *fdin;
   FILE *fdout;
   char* device = "/dev/com1";

   if ((fdout = fopen(device, "wb")) == NULL) {
      printf("Couldn't open '%s' for output\n", device);
      perror("open");
      exit(1);
   }
   if ((fdin = fopen(device, "rb")) == NULL) {
      printf("Couldn't open '%s' for input\n", device);
      perror("open");
      exit(1);
   }
}

-- 
Tomas Pihl                    Net Insight AB
tomas.pihl@netinsight.net     Box 42093, SE-126 14 STOCKHOLM, SWEDEN
Phone:  +46-8-685 04 95       Visiting address: Västberga Allé 9
Fax:    +46-8-685 04 20       http://www.netinsight.net

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Multiple fopens fails with permission denied
  2000-03-16  2:31 Multiple fopens fails with permission denied Tomas Pihl
@ 2000-03-16  8:45 ` Chris Faylor
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Faylor @ 2000-03-16  8:45 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1670 bytes --]

I don't believe that Windows allows you to open a com port twice
with both read and write access.

The usual way to deal with this is to open the file with "w+b"
options.  That provides a file pointer which can be both read to
and written from.

Be advised that the com port handling in B20.1 is not great, however.

cgf

On Thu, Mar 16, 2000 at 11:31:17AM +0100, Tomas Pihl wrote:
>I've installed B20.1 (full.exe) on a NT4.0 SP6 machine. When I try
>running the below included program I get:
>
>bash-2.02$ ./a.exe
>Couldn't open '/dev/com1' for input
>open: Permission denied
>
>It doesn't matter in which order I make the calls - fopen() always fail
>on the second fopen. Any ideas?
>
>int main()
>{
>   FILE *fdin;
>   FILE *fdout;
>   char* device = "/dev/com1";
>
>   if ((fdout = fopen(device, "wb")) == NULL) {
>      printf("Couldn't open '%s' for output\n", device);
>      perror("open");
>      exit(1);
>   }
>   if ((fdin = fopen(device, "rb")) == NULL) {
>      printf("Couldn't open '%s' for input\n", device);
>      perror("open");
>      exit(1);
>   }
>}
>
>-- 
>Tomas Pihl                    Net Insight AB
>tomas.pihl@netinsight.net     Box 42093, SE-126 14 STOCKHOLM, SWEDEN
>Phone:  +46-8-685 04 95       Visiting address: Västberga Allé 9
>Fax:    +46-8-685 04 20       http://www.netinsight.net
>
>--
>Want to unsubscribe from this list?
>Send a message to cygwin-unsubscribe@sourceware.cygnus.com
>

-- 
cgf@cygnus.com                        Cygnus Solutions, a Red Hat company
http://sourcware.cygnus.com/          http://www.redhat.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-03-16  8:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-16  2:31 Multiple fopens fails with permission denied Tomas Pihl
2000-03-16  8:45 ` Chris Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).