#include #include #include #include #include #include #include #include #include #include #define TARGETSIZE 80000 #define LIMSIZE 60000 #define PATTSIZE 27 int main(void) { struct rlimit lim; int fd; ssize_t retc; size_t count = 0; const char pattern[PATTSIZE] = "Hello world!"; signal(SIGXFSZ, SIG_IGN); lim.rlim_cur = LIMSIZE; setrlimit(RLIMIT_FSIZE, &lim); fd = open("result.txt", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); while (count < TARGETSIZE) { retc = write(fd, pattern, PATTSIZE); if (retc < PATTSIZE && retc > 0) fprintf(stderr, "added %zi bytes instead of %u bytes after %zu bytes\n", retc, PATTSIZE, count); else if (retc < 0) { fprintf(stderr, "failed when adding %u bytes after %zu bytes (error: %s)\n", PATTSIZE, count, strerror(errno)); break; } count += retc; } close(fd); return 0; }