diff --git a/Userland/sort.cpp b/Userland/sort.cpp index a8fa559fbe6..5eb520b1eb7 100644 --- a/Userland/sort.cpp +++ b/Userland/sort.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -44,9 +45,15 @@ int main(int argc, char** argv) Vector lines; for (;;) { - char buffer[BUFSIZ]; - auto* str = fgets(buffer, sizeof(buffer), stdin); - if (!str) + char* buffer = nullptr; + ssize_t buflen = 0; + errno = 0; + buflen = getline(&buffer, nullptr, stdin); + if (buflen == -1 && errno != 0) { + perror("getline"); + exit(1); + } + if (buflen == -1) break; lines.append(buffer); }