/** * SPDX-FileCopyrightText: Copyright (c) 2024-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: LicenseRef-NvidiaProprietary * * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual * property and proprietary rights in and to this material, related * documentation and any modifications thereto. Any use, reproduction, * disclosure or distribution of this material and related documentation * without an express license agreement from NVIDIA CORPORATION or * its affiliates is strictly prohibited. */ #include "wsl_utils.h" bool is_running_in_WSL(void) { static volatile bool verified = false; static volatile bool ret = false; if (!verified) { verified = true; FILE *versionFile = fopen("/proc/version", "r"); if (versionFile != NULL) { char versionInfo[512]; if (fgets(versionInfo, sizeof(versionInfo), versionFile) != NULL) { for (int i=0; versionInfo[i] != '\0'; i++) { versionInfo[i] = tolower((unsigned char)versionInfo[i]); } if (strstr(versionInfo, "microsoft") != NULL) { /* Yes, Running inside WSL */ ret = true; } } fclose(versionFile); } else { printf("ERROR: opening /proc/version failed\n"); } } return ret; }