replace O_SYNC with O_FSYNC
PATCH 1/1 replace O_SYNC with O_FSYNC
This patch replaces O_SYNC with O_FSYNC. These two flags do the same thing, but only O_FSYNC is available in Mac OS 10.3 and under. It only replaces O_SYNC if it doesn't exist. This patch allows the file block-raw-posix.c to compile on Mac OS 10.3. This is my first time submitting a patch, so there might have been a few mistakes made.
block-raw-posix (updated).c renamed from block-raw-posix.c +6 -0
@@ -73,6 +73,12 @@ #define DEBUG_BLOCK_PRINT(formatCstr, args...)#endif +// O_SYNC isn't available on Mac OS 10.3 and under +// O_SYNC and O_FSYNC do the same thing +#ifndef O_SYNC +#define O_SYNC O_FSYNC +#endif +/* OS X does not have O_DSYNC */ #ifndef O_DSYNC #define O_DSYNC O_SYNC
Hi,
Quoted 1 line · m a
This patch replaces
O_SYNCwithO_FSYNC. These two flags do the same thing, but onlyO_FSYNCis available in Mac OS 10.3 and under. It only replacesO_SYNCif it doesn't exist. This patch allows the fileblock-raw-posix.cto compile on Mac OS 10.3. This is my first time submitting a patch, so there might have been a few mistakes made.
Please include a Signed-off-by line and use C-style comments instead of C++ style comments. Otherwise, looks good.
Regards,
Anthony Liguori
Quoted 19 lines
block-raw-posix (updated).c Fri Jun 19 22:01:07 2009 renamed from block-raw-posix.c Wed May 20 16:46:58 2009 +6
-0@@ -73,6 +73,12 @@ #define DEBUG_BLOCK_PRINT(formatCstr, args...) #endif +// O_SYNC isn't available on Mac OS 10.3 and under +// O_SYNC and O_FSYNC do the same thing +#ifndef O_SYNC +#define O_SYNC O_FSYNC +#endif + /* OS X does not have O_DSYNC */ #ifndef O_DSYNC #define O_DSYNC O_SYNC
Quoted 1 line · Anthony Liguori
Please include a Signed-off-by line and use C-style comments instead of C++ style comments. Otherwise, looks good.
What do we have against C++ style comments?
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 6 lines · Anthony Liguori
Quoted 3 lines
Please include a Signed-off-by line and use C-style comments instead
of C++ style comments. Otherwise, looks good.What do we have against C++ style comments?
They are not valid in C code :P
François.
Quoted 11 lines · François Revol
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Please include a Signed-off-by line and use C-style comments instead
of C++ style comments. Otherwise, looks good.What do we have against C++ style comments?
They are not valid in C code :P
I think C99 allows them. Too bad date-related jokes are forbidden.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 8 lines · François Revol
Quoted 6 lines · Anthony Liguori
Quoted 3 lines
Please include a Signed-off-by line and use C-style comments instead
of C++ style comments. Otherwise, looks good.What do we have against C++ style comments?
They are not valid in C code :P
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Of course I still forbid them in my code too - they look wrong :-)
-- Jamie
Am 21.06.2009 um 01:25 schrieb Jamie Lokier:
Quoted 7 lines
Quoted 6 lines · François Revol
Quoted 5 lines · Anthony Liguori
Quoted 2 lines
Please [...] use C-style comments instead
of C++ style comments. [...]What do we have against C++ style comments?
Quoted 8 lines
Quoted 1 line
They are not valid in C code :P
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Gladly even ten-year-old GCC 2.95.x supports 'em. But even a recent GCC does not when compiled with -ansi, which is why system headers still mustn't use them.
Andreas
Quoted 3 lines
Of course I still forbid them in my code too - they look wrong :-)
-- Jamie
Quoted 17 lines · Andreas Färber
Am 21.06.2009 um 01:25 schrieb Jamie Lokier:
Quoted 14 lines
Quoted 7 lines · François Revol
Quoted 5 lines · Anthony Liguori
Quoted 2 lines
Please [...] use C-style comments instead
of C++ style comments. [...]What do we have against C++ style comments?
They are not valid in C code :P
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
Quoted 6 lines
Quoted 2 lines
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Gladly even ten-year-old GCC 2.95.x supports 'em. But even a recent GCC does not when compiled with -ansi, which is why system headers still mustn't use them.
This is wrong too. They can be used in system headers.
"gcc -ansi -pedantic -Wall -Werror" accepts C99 comments in system headers.
It just complains about them in your own code, since you asked it to. :-)
-- Jamie
Am 24.06.2009 um 20:25 schrieb Jamie Lokier:
Quoted 18 lines
Quoted 17 lines · Andreas Färber
Am 21.06.2009 um 01:25 schrieb Jamie Lokier:
Quoted 14 lines
Quoted 7 lines · François Revol
Quoted 5 lines · Anthony Liguori
Quoted 2 lines
Please [...] use C-style comments instead
of C++ style comments. [...]What do we have against C++ style comments?
They are not valid in C code :P
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Gladly even ten-year-old GCC 2.95.x supports 'em. But even a recent GCC does not when compiled with -ansi, which is why system headers still mustn't use them.
This is wrong too. They can be used in system headers.
No, that is wrong. freetype2 definitely complained when Haiku had C99 comments in its POSIX system headers. ;)
Andreas
Quoted 6 lines
"gcc -ansi -pedantic -Wall -Werror" accepts C99 comments in system headers.
It just complains about them in your own code, since you asked it to. :-)
-- Jamie
Quoted 26 lines · Andreas Färber
Am 24.06.2009 um 20:25 schrieb Jamie Lokier:
Quoted 23 lines
Quoted 22 lines · Andreas Färber
Am 21.06.2009 um 01:25 schrieb Jamie Lokier:
Quoted 18 lines
Quoted 9 lines · François Revol
Quoted 7 lines · Anthony Liguori
Quoted 3 lines
Please [...] use C-style comments instead
of C++ style comments. [...]What do we have against C++ style comments?
They are not valid in C code :P
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Gladly even ten-year-old GCC 2.95.x supports 'em. But even a recent GCC does not when compiled with -ansi, which is why system headers still mustn't use them.
This is wrong too. They can be used in system headers.
No, that is wrong. freetype2 definitely complained when Haiku had C99 comments in its POSIX system headers. ;)
#pragma GCC system_header
Best regards,
Filip Navara
Quoted 31 lines · Filip Navara
Quoted 30 lines · Andreas Färber
Am 24.06.2009 um 20:25 schrieb Jamie Lokier:
Quoted 27 lines
Quoted 25 lines · Andreas Färber
Am 21.06.2009 um 01:25 schrieb Jamie Lokier:
Quoted 11 lines
Quoted 9 lines · François Revol
Quoted 7 lines · Anthony Liguori
Quoted 3 lines
Please [...] use C-style comments instead
of C++ style comments. [...]What do we have against C++ style comments?
They are not valid in C code :P
Quoted 7 lines
Wrong.
Valid in GNU C for about 14 years, and ANSI/ISO C for about 10 years...
I'll be surprised if any C compiler used on any open source operating system, or any major commercial C compiler, doesn't accept them.
Gladly even ten-year-old GCC 2.95.x supports 'em. But even a recent GCC does not when compiled with -ansi, which is why system headers still mustn't use them.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
This is wrong too. They can be used in system headers.
No, that is wrong. freetype2 definitely complained when Haiku had C99 comments in its POSIX system headers. ;)
#pragma GCC
system_header
GCC has a notion of certain directories being system header directories.
So you don't need #pragma for headers in those, and if freetype2 was installed in them, that should have worked.
But if you install those headers in other places, then it doesn't treat them as system headers and becomes more strict about the language.
You can add more system header directories, but of course (nearly) everyone uses -Idir to add directories as that's well known and portable.
-- Jamie
Quoted 4 lines · Avi Kivity
Quoted 1 line · Anthony Liguori
Please include a Signed-off-by line and use C-style comments instead of C++ style comments. Otherwise, looks good.
What do we have against C++ style comments?
Just consistency:
anthony@squirrel:~/git/qemu$ grep '//' *.c | wc -l 163 anthony@squirrel:~/git/qemu$ grep '/\*' *.c | wc -l 5642
Nothing personal. I think the kernel has a policy of C89 comments only.
Regards,
Anthony Liguori
Quoted 4 lines · Anthony Liguori
Quoted 3 lines · Avi Kivity
Quoted 1 line · Anthony Liguori
Please include a Signed-off-by line and use C-style comments instead of C++ style comments. Otherwise, looks good.
Quoted 9 lines
Quoted 1 line
What do we have against C++ style comments?
Just consistency:
anthony@squirrel:~/git/qemu$ grep '//' *.c | wc -l 163 anthony@squirrel:~/git/qemu$ grep '/\*' *.c | wc -l 5642
Well, consistency trumps convenience.
Quoted 1 line
Nothing personal. I think the kernel has a policy of C89 comments only.
This isn't the kernel, we have our own coding style. But if we don't want C++ comments, that's fine.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · m a
This patch replaces
O_SYNCwithO_FSYNC. These two flags do the same thing, but onlyO_FSYNCis available in Mac OS 10.3 and under. It only replacesO_SYNCif it doesn't exist. This patch allows the fileblock-raw-posix.cto compile on Mac OS 10.3. This is my first time submitting a patch, so there might have been a few mistakes made.
But O_SYNC is a standard posix flag, while O_FSYNC appears to be a BSD extension. Also the actual code uses O_DSYNC anyway, which also is in Posix but not actually natively supported by some OSes, e.g. Linux (but still provided in libc there).
block-raw-posix (updated).c line 82
Quoted 13 lines
block-raw-posix (updated).c renamed from block-raw-posix.c +6
-0@@ -73,6 +73,12 @@ +// O_SYNC isn't available on Mac OS 10.3 and under +// O_SYNC and O_FSYNC do the same thing +#ifndef O_SYNC +#define O_SYNC O_FSYNC +#endif +/* OS X does not have O_DSYNC */ #ifndef O_DSYNC #define O_DSYNC O_SYNC
So if the code here is correct and Darwin is the only supported OS where O_DSYNC is missing we could just replace the O_SYNC in the last line with O_FSYNC.
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · m a
This patch replaces
O_SYNCwithO_FSYNC. These two flags do the same thing, but onlyO_FSYNCis available in Mac OS 10.3 and under. It only replacesO_SYNCif it doesn't exist. This patch allows the fileblock-raw-posix.cto compile on Mac OS 10.3. This is my first time submitting a patch, so there might have been a few mistakes made.But
O_SYNCis a standard posix flag, whileO_FSYNCappears to be a BSD extension. Also the actual code usesO_DSYNCanyway, which also is in Posix but not actually natively supported by some OSes, e.g. Linux (but still provided in libc there).
If O_FSYNC and O_SYNC do the same thing, and O_SYNC is used anywhere, there's no harm in this for portability:
#if !defined(O_SYNC) && defined(O_FSYNC)
#define O_SYNC O_FSYNC
#endifThe patch assumes O_FSYNC is defined if O_SYNC isn't, which is wrong.
Quoted 7 lines
Quoted 3 lines
/* OS X does not have
O_DSYNC*/
#ifndefO_DSYNC
#defineO_DSYNCO_SYNCSo if the code here is correct and Darwin is the only supported OS where
O_DSYNCis missing we could just replace theO_SYNCin the last line withO_FSYNC.
I agree, though the comment might be misleading, if there's another supported OS without O_DSYNC.
-- Jamie
Quoted 9 lines · Jamie Lokier
If
O_FSYNCandO_SYNCdo the same thing, andO_SYNCis used anywhere, there's no harm in this for portability:#if !defined(O_SYNC) && defined(O_FSYNC) #define O_SYNC O_FSYNC #endifThe patch assumes
O_FSYNCis defined ifO_SYNCisn't, which is wrong.
For what this patch is, it really isn't that important IMHO.
This is just a work around for a broken platform.
Regards,
Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Jamie Lokier
If
O_FSYNCandO_SYNCdo the same thing, andO_SYNCis used anywhere, there's no harm in this for portability:#if !defined(O_SYNC) && defined(O_FSYNC) #define O_SYNC O_FSYNC #endif
Quoted 7 lines
Quoted 2 lines
The patch assumes
O_FSYNCis defined ifO_SYNCisn't, which is wrong.For what this patch is, it really isn't that important IMHO.
This is just a work around for a broken platform.
Even though you are correct, did you have to add the 'broken platform' remark?
Quoted 2 lines · G 3 wrote:
Even though you are correct, did you have to add the 'broken platform' remark?
Well, O_SYNC is POSIX so anything which claims to be a unix and doesn't have O_SYNC is broken :-)
-- Jamie
Quoted 26 lines · Jamie Lokier
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · m a
This patch replaces
O_SYNCwithO_FSYNC. These two flags do the same thing, but onlyO_FSYNCis available in Mac OS 10.3 and under. It only replacesO_SYNCif it doesn't exist. This patch allows the fileblock-raw-posix.cto compile on Mac OS 10.3. This is my first time submitting a patch, so there might have been a few mistakes made.But
O_SYNCis a standard posix flag, whileO_FSYNCappears to be a BSD extension. Also the actual code usesO_DSYNCanyway, which also is in Posix but not actually natively supported by some OSes, e.g. Linux (but still provided in libc there).If
O_FSYNCandO_SYNCdo the same thing, andO_SYNCis used anywhere, there's no harm in this for portability:#if !defined(O_SYNC) && defined(O_FSYNC) #define O_SYNC O_FSYNC #endifThe patch assumes
O_FSYNCis defined ifO_SYNCisn't, which is wrong.Quoted 4 lines
Quoted 3 lines
/* OS X does not have
O_DSYNC*/
#ifndefO_DSYNC
#defineO_DSYNCO_SYNC
Quoted 10 lines
Quoted 3 lines
So if the code here is correct and Darwin is the only supported OS where
O_DSYNCis missing we could just replace theO_SYNCin the last line withO_FSYNC.I agree, though the comment might be misleading, if there's another supported OS without
O_DSYNC.-- Jamie
Your logic does make sense. I guess I should have done this instead:
#ifndef O_SYNC #ifdef O_FSYNC #define O_SYNC O_FSYNC #else #define O_SYNC 0 #endif
#endif
Defining O_SYNC as zero is ok because this flag is 'ORed' with other flags.