compat.cpp 647 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "compat.h"
  2. #include "progname.h"
  3. #include <util/generic/string.h>
  4. #ifdef _win_
  5. #include "winint.h"
  6. #include <io.h>
  7. #endif
  8. #ifndef HAVE_NATIVE_GETPROGNAME
  9. const char* getprogname() {
  10. return GetProgramName().data();
  11. }
  12. #endif
  13. #ifdef _win_
  14. void sleep(i64 len) {
  15. Sleep((unsigned long)len * 1000);
  16. }
  17. void usleep(i64 len) {
  18. Sleep((unsigned long)len / 1000);
  19. }
  20. #include <fcntl.h>
  21. int ftruncate(int fd, i64 length) {
  22. return _chsize_s(fd, length);
  23. }
  24. int truncate(const char* name, i64 length) {
  25. int fd = ::_open(name, _O_WRONLY);
  26. int ret = ftruncate(fd, length);
  27. ::close(fd);
  28. return ret;
  29. }
  30. #endif