| From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> | 
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
| Cc: | pgsql-hackers-win32(at)postgresql(dot)org | 
| Subject: | Re: Opening stdin/stdout in binary mode on Windows | 
| Date: | 2005-02-01 22:48:21 | 
| Message-ID: | 200502012248.j11MmLr04997@candle.pha.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general pgsql-hackers-win32 | 
Well, that is a nifty trick.  Great to have that solved with no
documentation changes required.
Without this fix we were going to have tons of headaches.
---------------------------------------------------------------------------
Tom Lane wrote:
> I wrote:
> > Can anyone suggest a way that does work to do binary I/O
> > on stdout?  What about reading from stdin?
> 
> After a bit of googling I came up with the attached patch.  I am not in
> a position to test it, however.  Can anyone try it out?
> 
> 			regards, tom lane
> 
> *** src/bin/pg_dump/pg_backup_archiver.c~	Tue Jan 25 17:44:31 2005
> --- src/bin/pg_dump/pg_backup_archiver.c	Wed Jan 26 13:34:33 2005
> ***************
> *** 29,34 ****
> --- 29,38 ----
>   #include <ctype.h>
>   #include <unistd.h>
>   
> + #ifdef WIN32
> + #include <io.h>
> + #endif
> + 
>   #include "pqexpbuffer.h"
>   #include "libpq/libpq-fs.h"
>   
> ***************
> *** 1709,1714 ****
> --- 1713,1731 ----
>   	AH->gzOut = 0;
>   	AH->OF = stdout;
>   
> + 	/*
> + 	 * On Windows, we need to use binary mode to read/write non-text archive
> + 	 * formats.  Force stdin/stdout into binary mode in case that is what
> + 	 * we are using.
> + 	 */
> + #ifdef WIN32
> + 	if (fmt != archNull)
> + 	{
> + 		setmode(fileno(stdout), O_BINARY);
> + 		setmode(fileno(stdin), O_BINARY);
> + 	}
> + #endif
> + 
>   #if 0
>   	write_msg(modulename, "archive format is %d\n", fmt);
>   #endif
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>       message can get through to the mailing list cleanly
> 
-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Christopher Browne | 2005-02-01 23:17:20 | Re: Postgresql and Athlon64 ? | 
| Previous Message | Niederland | 2005-02-01 22:30:57 | Re: postgresql.conf - add_missing_from | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Merlin Moncure | 2005-02-02 17:55:13 | Re: Opening stdin/stdout in binary mode on Windows | 
| Previous Message | Hiroshi Saito | 2005-02-01 20:18:22 | Re: simple doubt with shfolder.lib? |