Clean-up: default_pipe_size_getter: coding style adjustments
[lttng-tools.git] / tests / regression / tools / notification / default_pipe_size_getter.cpp
index cc24cec1ea01ea45bd34ecba5b8697d3d5d5409c..8615f769f842292be3597a75d4719d78394bb5ed 100644 (file)
@@ -9,19 +9,28 @@
  *
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <common/pipe.h>
-#include <common/error.h>
+#include <common/pipe.hpp>
+#include <common/error.hpp>
 
 int lttng_opt_verbose;
 int lttng_opt_mi;
 int lttng_opt_quiet;
 
-int main(int argc, const char **argv)
+namespace {
+#ifdef __linux__
+/*
+ * Return the default pipe buffer size or a negative error.
+ */
+int get_pipe_size(void)
 {
        int ret;
        /*
@@ -34,20 +43,40 @@ int main(int argc, const char **argv)
 
        if (!pipe) {
                /* lttng_pipe_open already logs on error. */
-               ret = EXIT_FAILURE;
+               ret = -1;
                goto end;
        }
 
        ret = fcntl(lttng_pipe_get_writefd(pipe), F_GETPIPE_SZ);
        if (ret < 0) {
                PERROR("Failed to get the size of the pipe");
-               ret = EXIT_FAILURE;
-               goto end;
        }
 
-       printf("%d\n", ret);
-       ret = EXIT_SUCCESS;
-end:
        lttng_pipe_destroy(pipe);
+end:
        return ret;
 }
+#elif defined(__FreeBSD__)
+int get_pipe_size(void)
+{
+       return 65536;
+}
+#else
+#error "Implement get_pipe_size() for your platform."
+#endif
+} /* namespace */
+
+int main(void)
+{
+       int ret;
+
+       ret = get_pipe_size();
+       if (ret < 0) {
+               return EXIT_FAILURE;
+       }
+
+       /* Print the pipe buffer size to stdout. */
+       printf("%d\n", ret);
+
+       return EXIT_SUCCESS;
+}
This page took 0.02747 seconds and 4 git commands to generate.