Modify README. Remove redundant assignment from overwrite.c.
Add additional error handling to overwrite.c.
This commit is contained in:
parent
cd3f05e0b8
commit
9d80a006d5
1
README
1
README
|
@ -13,4 +13,5 @@
|
||||||
line, so long as it doesn't cause a word-split.
|
line, so long as it doesn't cause a word-split.
|
||||||
-overwrite: Reads stdin and writes it to the provided file. [done]
|
-overwrite: Reads stdin and writes it to the provided file. [done]
|
||||||
-shuf: Accepts an arbitrary number of arguments; returns one at random.
|
-shuf: Accepts an arbitrary number of arguments; returns one at random.
|
||||||
|
-rand: Shell interface to the C rand() function.
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ int main(int argc, char **argv)
|
||||||
char *buf;
|
char *buf;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
strlen = 0;
|
strlen = 0;
|
||||||
buflen = 0;
|
|
||||||
/* arbitrary */
|
/* arbitrary */
|
||||||
buflen = 4096;
|
buflen = 4096;
|
||||||
|
|
||||||
|
@ -29,9 +28,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
for(;((c = getchar()) != EOF);)
|
for(;((c = getchar()) != EOF);)
|
||||||
{
|
{
|
||||||
if(strlen == buflen)
|
if(strlen == buflen && !(buf = realloc(buf, (buflen*=2))))
|
||||||
{
|
{
|
||||||
buf = realloc(buf, (buflen*=2));
|
/* realloc failed */
|
||||||
|
throw(MALLOC_FAIL, NULL);
|
||||||
}
|
}
|
||||||
buf[strlen++] = c;
|
buf[strlen++] = c;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue