pwd.c 492 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <limits.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #ifdef _WIN32
  5. #include <direct.h>
  6. #define getcurdir _getcwd
  7. #else
  8. #include <unistd.h>
  9. #define getcurdir getcwd
  10. #endif
  11. int main(int argc, char* argv[])
  12. {
  13. #define BUFSZ 20000
  14. char buf[BUFSZ + 1];
  15. #ifdef _WIN32
  16. char *pos;
  17. #endif
  18. getcurdir(buf, BUFSZ);
  19. #ifdef _WIN32
  20. pos = buf;
  21. while (*pos)
  22. {
  23. if (*pos == '\\')
  24. {
  25. *pos = '/';
  26. }
  27. ++pos;
  28. }
  29. #endif
  30. printf("%s\n", buf);
  31. return EXIT_SUCCESS;
  32. }