Skip to content

Commit

Permalink
Fix test on FreeBSD
Browse files Browse the repository at this point in the history
google/protobuf/testing/zcgzip.cc:61:25: error: unknown type name 'STDOUT_FILENO'
  FileOutputStream fout(STDOUT_FILENO);
                        ^
google/protobuf/testing/zcgzip.cc:61:24: warning: parentheses were disambiguated as a function declaration [-Wvexing-parse]
  FileOutputStream fout(STDOUT_FILENO);
                       ^~~~~~~~~~~~~~~
google/protobuf/testing/zcgzip.cc:61:25: note: add a pair of parentheses to declare a variable
  FileOutputStream fout(STDOUT_FILENO);
                        ^
                        (
google/protobuf/testing/zcgzip.cc:75:20: error: use of undeclared identifier 'STDIN_FILENO'
    readlen = read(STDIN_FILENO, outptr, outlen);
                   ^
1 warning and 2 errors generated.
gmake[3]: *** [Makefile:4009: google/protobuf/testing/zcgzip.o] Error 1

google/protobuf/testing/zcgunzip.cc:62:23: error: unknown type name 'STDIN_FILENO'
  FileInputStream fin(STDIN_FILENO);
                      ^
google/protobuf/testing/zcgunzip.cc:62:22: warning: parentheses were disambiguated as a function declaration [-Wvexing-parse]
  FileInputStream fin(STDIN_FILENO);
                     ^~~~~~~~~~~~~~
google/protobuf/testing/zcgunzip.cc:62:23: note: add a pair of parentheses to declare a variable
  FileInputStream fin(STDIN_FILENO);
                      ^
                      (
google/protobuf/testing/zcgunzip.cc:74:23: error: use of undeclared identifier 'STDOUT_FILENO'
      int err = write(STDOUT_FILENO, inptr, inlen);
                      ^
1 warning and 2 errors generated.
gmake[3]: *** [Makefile:4009: google/protobuf/testing/zcgunzip.o] Error 1

Reference:	https://bugs.FreeBSD.org/bugzilla/show_bug.cgi?id=215346
		https://svnweb.FreeBSD.org/changeset/ports/428734
  • Loading branch information
sunpoet authored and acozzette committed Jul 17, 2019
1 parent 744e799 commit 640b932
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/google/protobuf/testing/zcgunzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#ifdef _WIN32
#ifndef STDIN_FILENO
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/testing/zcgzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#ifdef _WIN32
#ifndef STDIN_FILENO
Expand Down

2 comments on commit 640b932

@gvanem
Copy link

@gvanem gvanem commented on 640b932 Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't anybody do tests on Windows/MSVC?
Those <unistd.h> should IMHO be moved outside the #ifdef _WIN32 section.

@gvanem
Copy link

@gvanem gvanem commented on 640b932 Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it with this patch:

--- a/zcgunzip.cc 2020-06-25 09:46:28
+++ b/zcgunzip.cc 2020-06-26 09:50:09
@@ -42,15 +42,18 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>

-#ifdef _WIN32
-#ifndef STDIN_FILENO
-#define STDIN_FILENO 0
-#endif
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
+#ifndef _WIN32
+  #include <unistd.h>
+#else
+  #include <io.h>
+
+  #ifndef STDIN_FILENO
+  #define STDIN_FILENO 0
+  #endif
+  #ifndef STDOUT_FILENO
+  #define STDOUT_FILENO 1
+  #endif
 #endif

 #include <google/protobuf/io/gzip_stream.h>
--- a/zcgzip.cc 2020-06-25 09:46:28
+++ b/zcgzip.cc 2020-06-26 09:48:36
@@ -41,15 +41,18 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>

-#ifdef _WIN32
-#ifndef STDIN_FILENO
-#define STDIN_FILENO 0
-#endif
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
-#endif
+#ifndef _WIN32
+  #include <unistd.h>
+#else
+  #include <io.h>
+
+  #ifndef STDIN_FILENO
+  #define STDIN_FILENO 0
+  #endif
+  #ifndef STDOUT_FILENO
+  #define STDOUT_FILENO 1
+  #endif
 #endif

 #include <google/protobuf/io/gzip_stream.h>

Please sign in to comment.