Esempio n. 1
0
char	*set_my_pwd(t_list *env)
{
  char	*pwd;

  pwd = my_pwd();
  my_setenv_lst(env, "PWD", pwd);
  return (pwd);
}
Esempio n. 2
0
void	put_pwd(t_info *info)
{
  char	*tab[4];

  tab[0] = "setenv";
  tab[1] = "PWD";
  tab[2] = my_pwd();
  tab[3] = NULL;
  my_setenv(info, tab);
  if (info->last_pwd != NULL)
    xfree(info->last_pwd);
  info->last_pwd = info->pwd;
  info->pwd = tab[2];
}
Esempio n. 3
0
int	execute(int sc)
{
  int	nb_read;
  char	buff[500];

  nb_read = read(sc, buff, 500);
  if (strncmp(buff, "ls", 2) == 0)
    my_ls(sc);
  else if (strncmp(buff, "pwd", 3) == 0)
    my_pwd(sc);
  else if (strncmp(buff, "quit", 4) == 0)
    return (0);
  else
    write(sc, "Commande not found", strlen("Commande not found"));
  return (1);
}
Esempio n. 4
0
//This tests the pwd function
//It does so by cd into different directories and calling the pwd function
//If the printed pwd does not match the expected pwd, returns 0.
int pwdTest()
{
  MINODE *test_mip = running->cwd;
  INODE *ip = NULL;
  int ino = 0;
  char expected1 [128] = "/";
  char expected2 [128] = "/X";
  char expected3 [128] = "/Y";
  char expected4 [128] = "/Y/Happydir3";

  strcpy(pathname, "");
  cd(pathname);
  test_mip = running->cwd;

  printf("\n\n-------- TESTING PWD FUNCTION --------\n\n");
  printf("Testing >pwd while in root\n");
  my_pwd();
  printf("Expected print: %s", expected1);
  printf("Expecteasdfasdd print: %s", teststr);

  if(strcmp(expected1, teststr))
  {
    printf("\nTEST FAILED!\n\n");
    return 0;
  }
  printf("TEST PASSED!\n\n");
  strcpy(teststr, "");

  printf("\ncd into X\n");
  strcpy(pathname, "X");
  cd(pathname);
  printf("Testing >pwd while in X\n");

  my_pwd();
  printf("Expected print: %s", expected2);
  if(strcmp(expected2, teststr))
  {
    printf("\nTEST FAILED!\n\n");
    return 0;
  }
  printf("\nTEST PASSED!\n\n");
  strcpy(teststr, "");


  printf("\ncd into /Y\n");
  strcpy(pathname, "/Y");
  cd(pathname);
  printf("Testing >pwd while in Y\n");

  my_pwd();
  printf("Expected print: %s", expected3);
  if(strcmp(expected3, teststr))
  {
    printf("\nTEST FAILED!\n\n");
    return 0;
  }
  printf("\nTEST PASSED!\n\n");
  strcpy(teststr, "");



  printf("\ncd into /Y/Happydir3\n");
  strcpy(pathname, "/Y/Happydir3");
  cd(pathname);
  printf("Testing >pwd while in /Y/Happydir3\n");

  my_pwd();
  printf("Expected print: %s", expected4);
  if(strcmp(expected4, teststr))
  {
    printf("\nTEST FAILED!\n\n");
    return 0;
  }
  printf("\nTEST PASSED!\n\n");

  strcpy(pathname, "");
  cd(pathname);

  printf("\n\nALL PWD TESTS PASSED!\n\n\n");
  return 1;
}