/* ** Reads a line from the standard input ** ** The line is terminated by a Ctrl+D or a '\n'. */ static t_hs read_line(void) { t_hs line; char c; line = hs_new_empty(); while (1) { c = read_char(); if (!c || c == '\n') break ; line = hs_concat_hs_char(line, c); } return (line); }
static t_hs get_hostname(void) { int fd; char c; t_hs host; host = hs(""); if ((fd = open_file(hs("/etc/hostname"), O_RDONLY)) == -1) return (hs("42sh")); while (42) { if (read(fd, &c, 1) == -1) { close(fd); return (hs("42sh")); } if (c == '\n' || c == '\0') break ; host = hs_concat_hs_char(host, c); } close(fd); return (host); }