main.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || \
  6. defined(__BORLANDC__) || defined(__MINGW32__))
  7. #include <direct.h>
  8. #include <io.h>
  9. #if defined(__WATCOMC__)
  10. #include <direct.h>
  11. #define _getcwd getcwd
  12. #endif
  13. static const char* Getcwd(char* buf, unsigned int len)
  14. {
  15. const char* ret = _getcwd(buf, len);
  16. char* p = NULL;
  17. if (!ret) {
  18. fprintf(stderr, "No current working directory.\n");
  19. abort();
  20. }
  21. // make sure the drive letter is capital
  22. if (strlen(buf) > 1 && buf[1] == ':') {
  23. buf[0] = toupper(buf[0]);
  24. }
  25. for (p = buf; *p; ++p) {
  26. if (*p == '\\') {
  27. *p = '/';
  28. }
  29. }
  30. return ret;
  31. }
  32. #else
  33. #include <fcntl.h>
  34. #include <sys/types.h>
  35. #include <unistd.h>
  36. static const char* Getcwd(char* buf, unsigned int len)
  37. {
  38. const char* ret = getcwd(buf, len);
  39. if (!ret) {
  40. fprintf(stderr, "No current working directory\n");
  41. abort();
  42. }
  43. return ret;
  44. }
  45. #endif
  46. int main(int argc, char* argv[])
  47. {
  48. char buf[2048];
  49. const char* cwd = Getcwd(buf, sizeof(buf));
  50. return strcmp(cwd, argv[1]);
  51. }