SupportBindings.cpp raw

   1  //go:build !purego
   2  
   3  //===- SupportBindings.cpp - Additional bindings for support --------------===//
   4  //
   5  // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
   6  // See https://llvm.org/LICENSE.txt for license information.
   7  // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
   8  //
   9  //===----------------------------------------------------------------------===//
  10  //
  11  // This file defines additional C bindings for the support component.
  12  //
  13  //===----------------------------------------------------------------------===//
  14  
  15  #include "SupportBindings.h"
  16  #include "llvm/Support/DynamicLibrary.h"
  17  #include <stdlib.h>
  18  #include <string.h>
  19  
  20  void LLVMLoadLibraryPermanently2(const char *Filename, char **ErrMsg) {
  21    std::string ErrMsgStr;
  22    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Filename, &ErrMsgStr)) {
  23      *ErrMsg = static_cast<char *>(malloc(ErrMsgStr.size() + 1));
  24      memcpy(static_cast<void *>(*ErrMsg),
  25             static_cast<const void *>(ErrMsgStr.c_str()), ErrMsgStr.size() + 1);
  26    }
  27  }
  28