main.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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__) || defined(__BORLANDC__) || defined(__MINGW32__))
  6. #include <io.h>
  7. #include <direct.h>
  8. #if defined(__WATCOMC__)
  9. #include <direct.h>
  10. #define _getcwd getcwd
  11. #endif
  12. static const char* Getcwd(char* buf, unsigned int len)
  13. {
  14. const char* ret = _getcwd(buf, len);
  15. char* p = NULL;
  16. if(!ret)
  17. {
  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. {
  24. buf[0] = toupper(buf[0]);
  25. }
  26. for(p = buf; *p; ++p)
  27. {
  28. if(*p == '\\')
  29. {
  30. *p = '/';
  31. }
  32. }
  33. return ret;
  34. }
  35. #else
  36. #include <sys/types.h>
  37. #include <fcntl.h>
  38. #include <unistd.h>
  39. static const char* Getcwd(char* buf, unsigned int len)
  40. {
  41. const char* ret = getcwd(buf, len);
  42. if(!ret)
  43. {
  44. fprintf(stderr, "No current working directory\n");
  45. abort();
  46. }
  47. return ret;
  48. }
  49. #endif
  50. int main(int argc, char *argv[])
  51. {
  52. char buf[2048];
  53. const char *cwd = Getcwd(buf, sizeof(buf));
  54. return strcmp(cwd, argv[1]);
  55. }