winlib.c 797 B

123456789101112131415161718192021222324252627282930
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file winlib.c
  7. *
  8. * \brief Find and load windows system libraries.
  9. *
  10. * We use this function to dynamically load code at runtime that might not be
  11. * available on all versions of Windows that we support.
  12. **/
  13. #ifdef _WIN32
  14. #include "lib/fs/winlib.h"
  15. HANDLE
  16. load_windows_system_library(const TCHAR *library_name)
  17. {
  18. TCHAR path[MAX_PATH];
  19. unsigned n;
  20. n = GetSystemDirectory(path, MAX_PATH);
  21. if (n == 0 || n + _tcslen(library_name) + 2 >= MAX_PATH)
  22. return 0;
  23. _tcscat(path, TEXT("\\"));
  24. _tcscat(path, library_name);
  25. return LoadLibrary(path);
  26. }
  27. #endif /* defined(_WIN32) */