[platform] native macOS environment reader: sources (IDEA-216133)

GitOrigin-RevId: e713b19c9e4bd6ecd74eeca7cbeb1fcd95b04e4a
This commit is contained in:
Roman Shevchenko
2021-06-16 15:44:00 +02:00
committed by intellij-monorepo-bot
parent d7c1d9b695
commit a79a4fdfd0
3 changed files with 44 additions and 0 deletions

2
native/MacEnvReader/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.idea/
/cmake-build-*/

View File

@@ -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)

View File

@@ -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 <stdio.h>
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;
}