Thread: xlog.c.patch for cygwin port.

xlog.c.patch for cygwin port.

From
"Alexei Zakharov"
Date:
Hello,
 
I've recently written to pgsql-ports about a problem with PG7.0 on NT (Subj: [PORTS] initdb problem on NT with 7.0).  Since nobody helped me, I had to find out the reson.  The difference between NT and Linux (for instance) is that "open( path, O_RDWR );" opens a file in text mode.  So sometime less block can be read than required.
 
I suggest a following patch.  BTW the situation appeared before, see hba.c, pqcomm.c and others.
 
Attachment

Re: [HACKERS] xlog.c.patch for cygwin port.

From
yutaka tanida
Date:
Hi,

On Mon, 6 Mar 2000 12:06:27 +0600
"Alexei Zakharov" <A.S.Zakharov@inp.nsk.su> wrote:

> I suggest a following patch.  BTW the situation appeared before, 
> see hba.c, pqcomm.c and others.

I propose another patch, against src/include/port/win.h.
If this patch is applied, #ifdef with open() such as following is no
more needed.

--
#ifndef __CYGWIN__ fd=open(path,flags,mode);
#else fd=open(path,flags | O_BINARY,mode);
#endif
--

Comments?

--
Yutaka tanida / S34 Co., Ltd.
tanida@s34.co.jp (Office)
yutaka@marin.or.jp(Private, or if you *HATE* Microsoft Outlook)



*** win.h.orig    Thu Feb 10 17:00:14 2000
--- win.h    Tue Mar 07 14:07:21 2000
***************
*** 10,15 ****
--- 10,35 ---- #define USE_POSIX_TIME #define HAVE_INT_TIMEZONE        /* has int _timezone */ 
+ /* open() must use with O_BINARY flag */
+ 
+ #include<stdarg.h>
+ #include<sys/fcntl.h>
+ 
+ static __inline int pg_cygwin_open(const char *pathname,int flags,...) {
+     va_list va;
+     mode_t mode;
+     if(flags | O_CREAT) {
+         va_start(va,flags);
+         mode=va_arg(va,int);
+         va_end(va);
+         return open(pathname,flags | O_BINARY,mode);
+     }else{
+         return open(pathname,flags | O_BINARY);
+     }
+ }
+ 
+ #define open pg_cygwin_open
+  #include <cygwin/version.h> #if (CYGWIN_VERSION_API_MAJOR >= 0) && (CYGWIN_VERSION_API_MINOR >= 8) #define sys_nerr
_sys_nerr



Re: [HACKERS] xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
Applied.

[Charset Windows-1252 unsupported, skipping...]

[Attachment, skipping...]


--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
This looks interesting.  We could remove some of our ifwin cruft.

---------------------------------------------------------------------------


On Mon, 6 Mar 2000 12:06:27 +0600
"Alexei Zakharov" <A.S.Zakharov@inp.nsk.su> wrote:

> I suggest a following patch.  BTW the situation appeared before, 
> see hba.c, pqcomm.c and others.

I propose another patch, against src/include/port/win.h.
If this patch is applied, #ifdef with open() such as following is no
more needed.

--
#ifndef __CYGWIN__ fd=open(path,flags,mode);
#else fd=open(path,flags | O_BINARY,mode);
#endif
--

Comments?

--
Yutaka tanida / S34 Co., Ltd.
tanida@s34.co.jp (Office)
yutaka@marin.or.jp(Private, or if you *HATE* Microsoft Outlook)



*** win.h.orig    Thu Feb 10 17:00:14 2000
--- win.h    Tue Mar 07 14:07:21 2000
***************
*** 10,15 ****
--- 10,35 ---- #define USE_POSIX_TIME #define HAVE_INT_TIMEZONE        /* has int _timezone */ 
+ /* open() must use with O_BINARY flag */
+ 
+ #include<stdarg.h>
+ #include<sys/fcntl.h>
+ 
+ static __inline int pg_cygwin_open(const char *pathname,int flags,...) {
+     va_list va;
+     mode_t mode;
+     if(flags | O_CREAT) {
+         va_start(va,flags);
+         mode=va_arg(va,int);
+         va_end(va);
+         return open(pathname,flags | O_BINARY,mode);
+     }else{
+         return open(pathname,flags | O_BINARY);
+     }
+ }
+ 
+ #define open pg_cygwin_open
+  #include <cygwin/version.h> #if (CYGWIN_VERSION_API_MAJOR >= 0) && (CYGWIN_VERSION_API_MINOR >= 8) #define sys_nerr
_sys_nerr


************


--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] xlog.c.patch for cygwin port.

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> This looks interesting.  We could remove some of our ifwin cruft.

I have been thinking for quite some time that most of the CYGWIN32
ifdefs represent very poor programming.  Instead of zillions of

#ifndef __CYGWIN32__fd = open(filename, O_RDONLY, 0666);
#elsefd = open(filename, O_RDONLY | O_BINARY, 0666);
#endif

we should have in one include file something like

#ifndef __CYGWIN32__
#define  OPEN_FLAGS_READ   O_RDONLY
#define  OPEN_FLAGS_WRITE  O_WRONLY
// etc for the combinations we need
#else
#define  OPEN_FLAGS_READ   (O_RDONLY | O_BINARY)
#define  OPEN_FLAGS_WRITE  (O_WRONLY | O_BINARY)
// etc
#endif

and then the body of the code would have
fd = open(filename, OPEN_FLAGS_READ, 0666);

and no ifdef.  This would also provide a single place to tweak open()
flags for other platforms, whereas the existing method is exactly zero
help for any non-CYGWIN platform that wants to add O_BINARY ...
        regards, tom lane


Re: [HACKERS] xlog.c.patch for cygwin port.

From
The Hermit Hacker
Date:
Sounds like a *great* bug fix to me ... if you "have better things to do",
I can tackle it ...

On Tue, 7 Mar 2000, Tom Lane wrote:

> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > This looks interesting.  We could remove some of our ifwin cruft.
> 
> I have been thinking for quite some time that most of the CYGWIN32
> ifdefs represent very poor programming.  Instead of zillions of
> 
> #ifndef __CYGWIN32__
>     fd = open(filename, O_RDONLY, 0666);
> #else
>     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> #endif
> 
> we should have in one include file something like
> 
> #ifndef __CYGWIN32__
> #define  OPEN_FLAGS_READ   O_RDONLY
> #define  OPEN_FLAGS_WRITE  O_WRONLY
> // etc for the combinations we need
> #else
> #define  OPEN_FLAGS_READ   (O_RDONLY | O_BINARY)
> #define  OPEN_FLAGS_WRITE  (O_WRONLY | O_BINARY)
> // etc
> #endif
> 
> and then the body of the code would have
> 
>     fd = open(filename, OPEN_FLAGS_READ, 0666);
> 
> and no ifdef.  This would also provide a single place to tweak open()
> flags for other platforms, whereas the existing method is exactly zero
> help for any non-CYGWIN platform that wants to add O_BINARY ...
> 
>             regards, tom lane
> 
> ************
> 

Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org 
primary: scrappy@hub.org           secondary: scrappy@{freebsd|postgresql}.org 



Re: [HACKERS] xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > This looks interesting.  We could remove some of our ifwin cruft.
> 
> I have been thinking for quite some time that most of the CYGWIN32
> ifdefs represent very poor programming.  Instead of zillions of
> 
> #ifndef __CYGWIN32__
>     fd = open(filename, O_RDONLY, 0666);
> #else
>     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> #endif
> 
> we should have in one include file something like

Do we ever assign a function pointer for open() anywhere.  If so, the
define will not work without some kind of wrapper, right?

--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] xlog.c.patch for cygwin port.

From
"D. Jay Newman"
Date:
>> Bruce Momjian <pgman@candle.pha.pa.us> writes:
>> > This looks interesting.  We could remove some of our ifwin cruft.
>> 
>> I have been thinking for quite some time that most of the CYGWIN32
>> ifdefs represent very poor programming.  Instead of zillions of
>> 
>> #ifndef __CYGWIN32__
>>     fd = open(filename, O_RDONLY, 0666);
>> #else
>>     fd = open(filename, O_RDONLY | O_BINARY, 0666);
>> #endif
>> 
>> we should have in one include file something like
>
>Do we ever assign a function pointer for open() anywhere.  If so, the
>define will not work without some kind of wrapper, right?

Since the only difference seems to be "O_RDONLY" vs "O_RDONLY | O_BINARY",
why not do the #define on that?

At least in this case it works.
-- 
D. Jay Newman                   ! For the pleasure and the profit it derives
jay@sprucegrove.com              ! I arrange things, like furniture, and
http://www.sprucegrove.com/~jay/   ! daffodils, and ...lives.  -- Hello Dolly


Re: [HACKERS] xlog.c.patch for cygwin port.

From
Tatsuo Ishii
Date:
> >> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> > This looks interesting.  We could remove some of our ifwin cruft.
> >> 
> >> I have been thinking for quite some time that most of the CYGWIN32
> >> ifdefs represent very poor programming.  Instead of zillions of
> >> 
> >> #ifndef __CYGWIN32__
> >>     fd = open(filename, O_RDONLY, 0666);
> >> #else
> >>     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> >> #endif
> >> 
> >> we should have in one include file something like
> >
> >Do we ever assign a function pointer for open() anywhere.  If so, the
> >define will not work without some kind of wrapper, right?
> 
> Since the only difference seems to be "O_RDONLY" vs "O_RDONLY | O_BINARY",
> why not do the #define on that?
> 
> At least in this case it works.

BTW, why do we call open() directory here? Why not VFD interface?
--
Tatsuo Ishii


Re: [HACKERS] xlog.c.patch for cygwin port.

From
The Hermit Hacker
Date:
On Tue, 7 Mar 2000, Bruce Momjian wrote:

> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > This looks interesting.  We could remove some of our ifwin cruft.
> > 
> > I have been thinking for quite some time that most of the CYGWIN32
> > ifdefs represent very poor programming.  Instead of zillions of
> > 
> > #ifndef __CYGWIN32__
> >     fd = open(filename, O_RDONLY, 0666);
> > #else
> >     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> > #endif
> > 
> > we should have in one include file something like
> 
> Do we ever assign a function pointer for open() anywhere.  If so, the
> define will not work without some kind of wrapper, right?

Okay, I'm lost ... if we "#define OPEN_FLAGS .." and not the open itself,
why would we need some kind of wrapper?




Re: [HACKERS] xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
> On Tue, 7 Mar 2000, Bruce Momjian wrote:
> 
> > > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > > This looks interesting.  We could remove some of our ifwin cruft.
> > > 
> > > I have been thinking for quite some time that most of the CYGWIN32
> > > ifdefs represent very poor programming.  Instead of zillions of
> > > 
> > > #ifndef __CYGWIN32__
> > >     fd = open(filename, O_RDONLY, 0666);
> > > #else
> > >     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> > > #endif
> > > 
> > > we should have in one include file something like
> > 
> > Do we ever assign a function pointer for open() anywhere.  If so, the
> > define will not work without some kind of wrapper, right?
> 
> Okay, I'm lost ... if we "#define OPEN_FLAGS .." and not the open itself,
> why would we need some kind of wrapper?

No, the original person was refining open().  I�think defining the flags
is much better.

--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: [HACKERS] xlog.c.patch for cygwin port.

From
The Hermit Hacker
Date:
On Wed, 8 Mar 2000, Bruce Momjian wrote:

> > On Tue, 7 Mar 2000, Bruce Momjian wrote:
> > 
> > > > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > > > This looks interesting.  We could remove some of our ifwin cruft.
> > > > 
> > > > I have been thinking for quite some time that most of the CYGWIN32
> > > > ifdefs represent very poor programming.  Instead of zillions of
> > > > 
> > > > #ifndef __CYGWIN32__
> > > >     fd = open(filename, O_RDONLY, 0666);
> > > > #else
> > > >     fd = open(filename, O_RDONLY | O_BINARY, 0666);
> > > > #endif
> > > > 
> > > > we should have in one include file something like
> > > 
> > > Do we ever assign a function pointer for open() anywhere.  If so, the
> > > define will not work without some kind of wrapper, right?
> > 
> > Okay, I'm lost ... if we "#define OPEN_FLAGS .." and not the open itself,
> > why would we need some kind of wrapper?
> 
> No, the original person was refining open().  I�think defining the flags
> is much better.
Ah, okay, knew I was missing something :)  




Re: xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
We have resolved all the open()/binary flag calls.



--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: xlog.c.patch for cygwin port.

From
Bruce Momjian
Date:
We have resolved all the O_BINARY calls for 7.1.  Thanks.


> On Mon, 6 Mar 2000 12:06:27 +0600
> "Alexei Zakharov" <A.S.Zakharov@inp.nsk.su> wrote:
> 
> > I suggest a following patch.  BTW the situation appeared before, 
> > see hba.c, pqcomm.c and others.
> 
> I propose another patch, against src/include/port/win.h.
> If this patch is applied, #ifdef with open() such as following is no
> more needed.
> 
> --
> #ifndef __CYGWIN__
>   fd=open(path,flags,mode);
> #else
>   fd=open(path,flags | O_BINARY,mode);
> #endif

--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026