shell_pwd.c 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * shell_pwd.c
  3. */
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. #include "lub/string.h"
  7. #include "private.h"
  8. /*--------------------------------------------------------- */
  9. void
  10. clish_shell__set_pwd(clish_shell_t * this, unsigned index, const char *element)
  11. {
  12. char **tmp;
  13. size_t new_size = 0;
  14. unsigned i;
  15. if (index >= this->cfg_pwdc) {
  16. /* create new element */
  17. new_size = (index + 1) * sizeof(char *);
  18. /* resize the pwd vector */
  19. tmp = realloc(this->cfg_pwdv, new_size);
  20. assert(tmp);
  21. this->cfg_pwdv = tmp;
  22. for (i = this->cfg_pwdc; i <= index; i++)
  23. this->cfg_pwdv[i] = NULL;
  24. this->cfg_pwdc = index + 1;
  25. }
  26. lub_string_free(this->cfg_pwdv[index]);
  27. this->cfg_pwdv[index] = lub_string_dup(element);
  28. }
  29. const char *clish_shell__get_pwd(const clish_shell_t * this, unsigned index)
  30. {
  31. if (index >= this->cfg_pwdc)
  32. return NULL;
  33. return this->cfg_pwdv[index];
  34. }
  35. conf_client_t *clish_shell__get_client(const clish_shell_t * this)
  36. {
  37. return this->client;
  38. }