mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Userland/sort: Convert sort to use getline
Sort uses a statically sized buffer. This commit changes that to use getline, so lines of any size will be handled properly.
This commit is contained in:
parent
0c2327b5b8
commit
212aa85a55
1 changed files with 10 additions and 3 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <AK/QuickSort.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -44,9 +45,15 @@ int main(int argc, char** argv)
|
|||
Vector<String> 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue