Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mac OS X build - alternate fdatasync() implementation #145

Closed
GoogleCodeExporter opened this issue Oct 14, 2015 · 6 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Mac OS X does not implement fdatasync.  The closest equivalent would seem to be 
fcntl(fd, F_FULLFSYNC)

Index: cstdlib/unistd.c
===================================================================
--- cstdlib/unistd.c    (revision 572)
+++ cstdlib/unistd.c    (working copy)
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <limits.h>
+#include <fcntl.h>
 #include "../interpreter.h"

 #ifndef BUILTIN_MINI_STDLIB
@@ -82,7 +83,12 @@

 void UnistdFdatasync(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
 {
+#ifdef F_FULLFSYNC
+    /* this is a Mac OS X system which does not implement fdatasync as such */
+    ReturnValue->Val->Integer = fcntl(Param[0]->Val->Integer, F_FULLFSYNC);
+#else
     ReturnValue->Val->Integer = fdatasync(Param[0]->Val->Integer);
+#endif
 }

 void UnistdFork(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)

Original issue reported on code.google.com by [email protected] on 13 Nov 2011 at 2:55

@GoogleCodeExporter
Copy link
Author

fdatasync() appears to be implemented in current Mac OS X.

Original comment by [email protected] on 1 Mar 2014 at 4:36

  • Changed state: WontFix

@GoogleCodeExporter
Copy link
Author

It isn't. The only mention of fdatasync() is in <sys/sysproto.h>, as a system 
call; it is not implemented at the library level.

Please re-consider not fixing this; the patch included above has worked well 
for me, and it is correct for both current and older OS X versions.


Original comment by [email protected] on 1 Mar 2014 at 7:55

@GoogleCodeExporter
Copy link
Author

picoc compiles without modification on my mac. Here's what I see:

$ make
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o picoc.o 
picoc.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o table.o 
table.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o lex.o lex.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o parse.o 
parse.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
expression.o expression.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o heap.o 
heap.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o type.o 
type.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o variable.o 
variable.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o clibrary.o 
clibrary.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o platform.o 
platform.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o include.o 
include.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o debug.o 
debug.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
platform/platform_unix.o platform/platform_unix.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
platform/library_unix.o platform/library_unix.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/stdio.o cstdlib/stdio.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/math.o cstdlib/math.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/string.o cstdlib/string.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/stdlib.o cstdlib/stdlib.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/time.o cstdlib/time.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/errno.o cstdlib/errno.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/ctype.o cstdlib/ctype.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/stdbool.o cstdlib/stdbool.c
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\"   -c -o 
cstdlib/unistd.o cstdlib/unistd.c
cstdlib/unistd.c:85:33: warning: implicit declaration of function 'fdatasync' 
is invalid in C99 [-Wimplicit-function-declaration]
    ReturnValue->Val->Integer = fdatasync(Param[0]->Val->Integer);
                                ^
cstdlib/unistd.c:266:33: warning: 'sbrk' is deprecated 
[-Wdeprecated-declarations]
    ReturnValue->Val->Pointer = sbrk(Param[0]->Val->Integer);
                                ^
/usr/include/unistd.h:582:7: note: 'sbrk' declared here
void    *sbrk(int);
         ^
2 warnings generated.
gcc -Wall -pedantic -g -DUNIX_HOST -DVER=\"`svnversion -n`\" -o picoc picoc.o 
table.o lex.o parse.o expression.o heap.o type.o variable.o clibrary.o 
platform.o include.o debug.o platform/platform_unix.o platform/library_unix.o 
cstdlib/stdio.o cstdlib/math.o cstdlib/string.o cstdlib/stdlib.o cstdlib/time.o 
cstdlib/errno.o cstdlib/ctype.o cstdlib/stdbool.o cstdlib/unistd.o -lm 
-lreadline


Am I missing something here?

Original comment by [email protected] on 2 Mar 2014 at 12:09

  • Changed state: New

@GoogleCodeExporter
Copy link
Author

As I noted above, fdatasync isn't implemented at the library level, it's a 
system call and it doesn't take the arguments you're assuming it does.

You don't have a prototype in scope (see the warning, which should be an error) 
and what you're actually linking against is the system call stub:

_fdatasync:
00000000000161d8        movl    $0x20000bb, %eax
00000000000161dd        movq    %rcx, %r10
00000000000161e0        syscall
00000000000161e2        jae     0x161ec
00000000000161e4        movq    %rax, %rdi
00000000000161e7        jmpq    _cerror
00000000000161ec        ret

from <sys/sysproto.h>

struct fdatasync_args {
        char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
};
...
int fdatasync(struct proc *, struct fdatasync_args *, int *);


For whatever reason, it's not surfaced anywhere in a user-callable fashion. The 
F_FULLFSYNC fcntl is the standard mechanism for achieving the equivalent 
functionality on OS X.

Original comment by [email protected] on 2 Mar 2014 at 12:48

@GoogleCodeExporter
Copy link
Author

Oh I see. Thanks for that.

Fixed in r608.

Original comment by [email protected] on 2 Mar 2014 at 1:34

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thanks!

Original comment by [email protected] on 2 Mar 2014 at 1:35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant