You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mk_util.cpp 1.5KB

8 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <cstdarg>
  11. #include <cassert>
  12. #include "mk_util.h"
  13. #include "Util/util.h"
  14. #include "Util/logger.h"
  15. using namespace std;
  16. using namespace toolkit;
  17. #ifndef _WIN32
  18. #define _strdup strdup
  19. #endif
  20. API_EXPORT char* API_CALL mk_util_get_exe_path(){
  21. return _strdup(exePath().data());
  22. }
  23. API_EXPORT char* API_CALL mk_util_get_exe_dir(const char *relative_path){
  24. if(relative_path){
  25. return _strdup((exeDir() + relative_path).data());
  26. }
  27. return _strdup(exeDir().data());
  28. }
  29. API_EXPORT uint64_t API_CALL mk_util_get_current_millisecond(){
  30. return getCurrentMillisecond();
  31. }
  32. API_EXPORT char* API_CALL mk_util_get_current_time_string(const char *fmt){
  33. assert(fmt);
  34. return _strdup(getTimeStr(fmt).data());
  35. }
  36. API_EXPORT char* API_CALL mk_util_hex_dump(const void *buf, int len){
  37. assert(buf && len > 0);
  38. return _strdup(hexdump(buf,len).data());
  39. }
  40. API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) {
  41. va_list ap;
  42. va_start(ap, fmt);
  43. toolkit::LoggerWrapper::printLogV(getLogger(), level, file, function, line, fmt, ap);
  44. va_end(ap);
  45. }