I'm trying to write test, in which some data should be read from file descriptor, so i'm using dup and pipe functions to check this.
int main()
{
char *line;
int out;
int p[2];
char *str;
int len = 50;
str = (char *)malloc(235436);
for (int i = 0; i < 235436; ++i)
{
str[i]='h';
}
out = dup(1);
pipe(p);
dup2(p[1], 1);
write(1, str, strlen(str)); //freezes there. malloc alocates memory, i've checked this with debuger
close(p[1]);
dup2(out, 1);
get_next_line(p[0], &line);
}
And for some reason this code works perfectly although it does all the same.
str = (char *)malloc(1000 * 1000);
*str = '\0';
while (len--)
strcat(str, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur in leo dignissim, gravida leo id, imperdiet urna. Aliquam magna nunc, maximus quis eleifend et, scelerisque non dolor. Suspendisse augue augue, tempus");
out = dup(1);
pipe(p);
dup2(p[1], 1);
if (str)
write(1, str, strlen(str));
close(p[1]);
dup2(out, 1);
get_next_line(p[0], &line);