From a79a4fdfd0883518d9d8521c0039ac19b723b3fb Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 16 Jun 2021 15:44:00 +0200 Subject: [PATCH] [platform] native macOS environment reader: sources (IDEA-216133) GitOrigin-RevId: e713b19c9e4bd6ecd74eeca7cbeb1fcd95b04e4a --- native/MacEnvReader/.gitignore | 2 ++ native/MacEnvReader/CMakeLists.txt | 14 ++++++++++++++ native/MacEnvReader/printenv.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 native/MacEnvReader/.gitignore create mode 100644 native/MacEnvReader/CMakeLists.txt create mode 100644 native/MacEnvReader/printenv.c diff --git a/native/MacEnvReader/.gitignore b/native/MacEnvReader/.gitignore new file mode 100644 index 000000000000..7b6e9d57b180 --- /dev/null +++ b/native/MacEnvReader/.gitignore @@ -0,0 +1,2 @@ +/.idea/ +/cmake-build-*/ diff --git a/native/MacEnvReader/CMakeLists.txt b/native/MacEnvReader/CMakeLists.txt new file mode 100644 index 000000000000..6d57de7697a0 --- /dev/null +++ b/native/MacEnvReader/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1) +project(MacEnvReader C) + +if (NOT APPLE) + message(FATAL_ERROR "macOS only.") +endif () + +set(CMAKE_C_STANDARD 11) +set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9) + +add_compile_options("-fno-objc-arc" "-flto=full" "-Wall" "-Wextra" "-Wpedantic") + +add_executable(printenv printenv.c) diff --git a/native/MacEnvReader/printenv.c b/native/MacEnvReader/printenv.c new file mode 100644 index 000000000000..9fb0a4ac9fe0 --- /dev/null +++ b/native/MacEnvReader/printenv.c @@ -0,0 +1,28 @@ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. +// Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + +#include + +int main(int argc, const char **argv, const char **env) { + if (argc != 2) { + printf("usage: %s output_file\n", argv[0]); + return 1; + } + + FILE *f = fopen(argv[1], "w"); + if (f == NULL) { + perror("fopen"); + return 2; + } + + const char **v = env; + while (*v != NULL) { + fputs(*v, f); + fputc('\0', f); + v++; + } + + fclose(f); + + return 0; +}