Improve git. It's more beta quality now -- it's actually compliant, but

maybe a bit messier than it needs to be.
This commit is contained in:
Mid Favila 2022-08-14 14:34:31 -04:00
parent e8c4b477b9
commit 0289a812f5

View File

@ -17,25 +17,31 @@ char *cat(FILE *fp, const int mode, long unsigned *bufsize)
if(!mode)
{
static long unsigned int i, buflen;
buflen = 4096;
char *arr = malloc(buflen);
char *newarr = 0;
static long unsigned int i, finalbuflen, tmpbuflen;
tmpbuflen = 4096;
char *arr = malloc(tmpbuflen);
char *tmparr = 0;
char *finalarr = 0;
for(i = 0; (c = fgetc(fp)) != EOF; i++)
for(i = 0, finalbuflen = 0; (c = fgetc(fp)) != EOF; i++, finalbuflen++)
{
if(i >= buflen)
if(i >= tmpbuflen)
{
buflen *= 2;
newarr = malloc(buflen);
memcpy(newarr, arr, buflen/2);
tmpbuflen *= 2;
tmparr = malloc(tmpbuflen);
memcpy(tmparr, arr, tmpbuflen/2);
free(arr);
arr = newarr;
arr = tmparr;
}
arr[i] = c;
}
*bufsize = buflen;
finalarr = malloc(finalbuflen);
memcpy(finalarr, arr, finalbuflen);
free(arr);
arr = finalarr;
*bufsize = finalbuflen;
return arr;
}
else
@ -70,12 +76,13 @@ int main(int argc, char **argv)
if(!strcmp(argv[i], "-"))
{
fppresence++;
newbuf = cat(stdin, upresence, &newbuflen);
newbuf = cat(fopen("/dev/stdin", "r"), upresence, &newbuflen);
}
else if((fp = fopen(argv[i], "r")) != NULL)
{
fppresence++;
newbuf = cat(fp, upresence, &newbuflen);
fclose(fp);
}
else
{
@ -92,11 +99,13 @@ int main(int argc, char **argv)
free(buf);
buf = tmpbuf;
}
}
if(!fppresence)
{
buf = cat(stdin, upresence, &newbuflen);
buf = cat(fopen("/dev/stdin", "r"), upresence, &buflen);
}
if(!upresence)