Fix formatting.

This commit is contained in:
bʰedoh₂ swé 2024-06-18 05:01:37 +05:00
parent b666de95af
commit f4791c5177
2 changed files with 29 additions and 18 deletions

View File

@ -3,46 +3,57 @@
#include <stdlib.h>
#include "wincompat.h"
size_t getline(char **lineptr, size_t *n, FILE *stream) {
size_t getline(char **lineptr, size_t *n, FILE *stream)
{
char *bufptr = NULL;
char *p = bufptr;
size_t size;
int c;
if (lineptr == NULL) {
if (lineptr == NULL)
{
return -1;
}
if (stream == NULL) {
if (stream == NULL)
{
return -1;
}
if (n == NULL) {
if (n == NULL)
{
return -1;
}
bufptr = *lineptr;
size = *n;
c = fgetc(stream);
if (c == EOF) {
if (c == EOF)
{
return -1;
}
if (bufptr == NULL) {
if (bufptr == NULL)
{
bufptr = malloc(128);
if (bufptr == NULL) {
if (bufptr == NULL)
{
return -1;
}
size = 128;
}
p = bufptr;
while(c != EOF) {
if ((p - bufptr) > (size - 1)) {
while (c != EOF)
{
if ((p - bufptr) > (size - 1))
{
size = size + 128;
bufptr = realloc(bufptr, size);
if (bufptr == NULL) {
if (bufptr == NULL)
{
return -1;
}
}
*p++ = c;
if (c == '\n') {
if (c == '\n')
{
break;
}
c = fgetc(stream);