...
Code Block | ||
---|---|---|
| ||
int copy_file(FILE *src, FILE *dst, size_t bufsize) { char buf[bufsize]; while (fgets(buf, bufsize, src)) { if (fputs(buf, dst); == EOF) { /* Handle Error */ } } return 0; } |
Wiki Markup |
---|
The BSD extension function {{alloca()}} behaves in a similar fashion to VLAs; its use is not recommended \[[Loosemore 07|AA. C References#Loosemore 07]\] . |
...
Code Block | ||
---|---|---|
| ||
int copy_file(FILE *src, FILE *dst, size_t bufsize) { if (bufsize == 0) { /* Handle Error */ } char *buf = (char *)malloc(bufsize); if (!buf) { return -1; } while (fgets(buf, bufsize, src)) { if (fputs(buf, dst); == EOF) { /* Handle Error */ } } /* ... */ free(buf); return 0; } |
...