pwd.c 478 B

1234567891011121314151617181920212223242526272829303132
  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. if (*pos == '\\') {
  23. *pos = '/';
  24. }
  25. ++pos;
  26. }
  27. #endif
  28. printf("%s\n", buf);
  29. return EXIT_SUCCESS;
  30. }