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:
parent
e8c4b477b9
commit
0289a812f5
35
src/cat.c
35
src/cat.c
@ -17,25 +17,31 @@ char *cat(FILE *fp, const int mode, long unsigned *bufsize)
|
|||||||
|
|
||||||
if(!mode)
|
if(!mode)
|
||||||
{
|
{
|
||||||
static long unsigned int i, buflen;
|
static long unsigned int i, finalbuflen, tmpbuflen;
|
||||||
buflen = 4096;
|
tmpbuflen = 4096;
|
||||||
char *arr = malloc(buflen);
|
char *arr = malloc(tmpbuflen);
|
||||||
char *newarr = 0;
|
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;
|
tmpbuflen *= 2;
|
||||||
newarr = malloc(buflen);
|
tmparr = malloc(tmpbuflen);
|
||||||
memcpy(newarr, arr, buflen/2);
|
memcpy(tmparr, arr, tmpbuflen/2);
|
||||||
free(arr);
|
free(arr);
|
||||||
arr = newarr;
|
arr = tmparr;
|
||||||
}
|
}
|
||||||
|
|
||||||
arr[i] = c;
|
arr[i] = c;
|
||||||
}
|
}
|
||||||
*bufsize = buflen;
|
|
||||||
|
finalarr = malloc(finalbuflen);
|
||||||
|
memcpy(finalarr, arr, finalbuflen);
|
||||||
|
free(arr);
|
||||||
|
arr = finalarr;
|
||||||
|
*bufsize = finalbuflen;
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -70,12 +76,13 @@ int main(int argc, char **argv)
|
|||||||
if(!strcmp(argv[i], "-"))
|
if(!strcmp(argv[i], "-"))
|
||||||
{
|
{
|
||||||
fppresence++;
|
fppresence++;
|
||||||
newbuf = cat(stdin, upresence, &newbuflen);
|
newbuf = cat(fopen("/dev/stdin", "r"), upresence, &newbuflen);
|
||||||
}
|
}
|
||||||
else if((fp = fopen(argv[i], "r")) != NULL)
|
else if((fp = fopen(argv[i], "r")) != NULL)
|
||||||
{
|
{
|
||||||
fppresence++;
|
fppresence++;
|
||||||
newbuf = cat(fp, upresence, &newbuflen);
|
newbuf = cat(fp, upresence, &newbuflen);
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -92,11 +99,13 @@ int main(int argc, char **argv)
|
|||||||
free(buf);
|
free(buf);
|
||||||
buf = tmpbuf;
|
buf = tmpbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fppresence)
|
if(!fppresence)
|
||||||
{
|
{
|
||||||
buf = cat(stdin, upresence, &newbuflen);
|
buf = cat(fopen("/dev/stdin", "r"), upresence, &buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!upresence)
|
if(!upresence)
|
||||||
|
Loading…
Reference in New Issue
Block a user