#include #include #include #include #include #include int main(void) { void *p; const struct rlimit rlim_data = { .rlim_cur = 10 << 20, .rlim_max = RLIM_INFINITY }; int saved_errno; p = sbrk(0); fprintf(stderr, "sbrk=%p main=%p\n", p, &main); if (setrlimit(RLIMIT_DATA, &rlim_data) == -1) { fprintf(stderr, "setrlimit failed: %s\n", strerror(errno)); return 1; } if (sbrk(1 << 20) == (void*)-1) { saved_errno = errno; fprintf(stderr, "sbrk failed: %s (brk=%p)\n", strerror(saved_errno), sbrk(0)); return 1; } else { fprintf(stderr, "sbrk succeeded (brk=%p)\n", sbrk(0)); return 0; } }