chdir.c 634 B

123456789101112131415161718192021222324252627
  1. #include <limits.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "test_helpers.h"
  6. int main(void) {
  7. char cwd[PATH_MAX] = { 0 };
  8. char *cwd_result = NULL;
  9. cwd_result = getcwd(cwd, PATH_MAX);
  10. ERROR_IF(getcwd, cwd_result, == NULL);
  11. UNEXP_IF(getcwd, cwd_result, != cwd);
  12. printf("getcwd before chdir: %s\n", cwd);
  13. int status = chdir("..");
  14. ERROR_IF(chdir, status, == -1);
  15. UNEXP_IF(chdir, status, != 0);
  16. cwd_result = getcwd(cwd, PATH_MAX);
  17. ERROR_IF(getcwd, cwd_result, == NULL);
  18. UNEXP_IF(getcwd, cwd_result, != cwd);
  19. printf("getcwd after chdir: %s\n", cwd);
  20. }