commands.c 538 B

123456789101112131415161718192021222324252627
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. */
  5. /* POSIX Header Files */
  6. #include <unistd.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #include <string.h>
  10. /* sh Header Files */
  11. #include "commands.h"
  12. int builtin_cd(int argc, char *argv[]);
  13. /* *** COMMANDS *** */
  14. /* cd - change directory */
  15. int builtin_cd(int argc, char *argv[]) {
  16. if (argc > 1 && chdir(argv[1]) == -1 && errno) {
  17. printf("sh: cd: %s\n", strerror(errno));
  18. return errno;
  19. }
  20. return 0;
  21. }