int cdFeat(t_root *cmd) { int error; char *pwd; char *oldpwd; error = 0; if (cmd->CmdArray[1] == NULL) return (cdHomeDir(cmd)); else if (my_strcmp(cmd->CmdArray[1], "-") == 0) { free(cmd->CmdArray[1]); if ((cmd->CmdArray[1] = my_strdup(getEnv("OLDPWD", cmd->Env)) ) == NULL) return (-1); my_putstr_fd(getEnv("OLDPWD", cmd->Env), cmd->fd[1]); my_putstr_fd("\n", cmd->fd[1]); } if (cmd->CmdArray[1] != NULL) { oldpwd = getcwd(NULL, 512); error = chdir(cmd->CmdArray[1]); pwd = getcwd(NULL, 512); } if (displayErrorDir(error, cmd, pwd, oldpwd) == -1) return (-1); return (0); }
void client_unreachable(void) { g_pid = -1; my_putstr_fd("\033[31m [\033[0m", 2); my_putnbr_fd(g_pid, 2); my_putstr_fd("\033[31m] cannot reach client, abort\n", 2); signal(SIGUSR1, &sig_receive_pid); signal(SIGUSR2, &sig_receive_pid); }
t_uint my_put_nbr_fd(int fd, int nbr) { t_uint printed; printed = 0; if (nbr == -2147483648) { printed += my_putstr_fd(fd, "-2147483648"); return (11); } if (nbr < 0) { my_putchar_fd(fd, '-'); printed += 1; nbr = nbr * -1; } if (nbr >= 10) { printed += my_put_nbr_fd(fd, nbr / 10); my_putchar_fd(fd, nbr % 10 + '0'); printed += 1; } else printed += my_putchar_fd(fd, nbr + '0'); return (printed); }
int clean_term() { char *cmd; move_abs(0, 0); if ((cmd = tgetstr("cd", NULL)) == NULL) { my_putstr_error("Error, while cleaning the screen\n"); return (0); } my_putstr_fd(cmd); return (1); }
int move_abs(int x, int y) { char *cap; cap = tgetstr("cm", NULL); if (cap != NULL) cap = tgoto(cap, x, y); if (cap != NULL) { my_putstr_fd(cap); return (1); } return (0); }
t_uint my_putnbr_printf(int fd, int nbr) { t_uint printed; printed = 0; if (nbr == -2147483648) { printed += my_putstr_fd(fd, "-2147483648"); return (printed); } if (nbr < 0) { printed += my_putchar_fd(fd, '-'); nbr = nbr * -1; } printed += my_put_nbr_fd(fd, nbr); return (printed); }
void write_on_the_rest(int fd, char *buf, int len, int max) { int c; char fdbis[3]; c = 4; bzero(fdbis, 3); while (c < max) { if (c != fd) { write(c, "perso ", 6); sprintf(fdbis, "%d", fd); my_putstr_fd(fdbis, c); write(c, " say :", 6); write(c, buf, len); } c++; } }
int new_client(int fd, t_irc *info) { int new_fd; struct sockaddr_in client_sin; socklen_t size; t_usr *cpy; t_usr **cpy2; cpy2 = NULL; cpy = NULL; size = sizeof(struct sockaddr_in); new_fd = accept(fd, (struct sockaddr *)&client_sin, &size); if (new_fd >= FDMAX) { my_putstr_fd("sorry too much connection... \n", new_fd); close (new_fd); return (1); } info->fd_type[new_fd] = 'c'; return (0); }
t_uint my_putstr(const char *str) { return (my_putstr_fd(STDOUT, str)); }
void my_putstr(const char *s) { if (s) my_putstr_fd(s, 1); }