Advertisement
SamPolyhedron

Exam_GNL

Mar 22nd, 2022 (edited)
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. /* Библиотеки для get_next_line */
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4.  
  5. char    *get_next_line(int fd)
  6. {
  7.     char    *line = malloc(10000);
  8.     int     i = 0;
  9.  
  10.     if (read(fd, &line[i++], 1) < 1 && (i = -1))
  11.         free(line);
  12.     while (i != -1 && read(fd, &line[i], 1) > 0 && line[i] != '\n')
  13.         line[++i + 1] = '\0';
  14.     if (i == -1)
  15.         return (NULL);
  16.     return (line);
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement