File: test-limits.c

package info (click to toggle)
unison-2.53 2.53.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,876 kB
  • sloc: ml: 38,891; objc: 3,577; ansic: 3,122; python: 430; makefile: 223; sh: 205
file content (36 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * test-limit.c: Test memory size limits.
 * Allocate memory until failure.
 * Print amount allocated.
 *
 * https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ulimit.html
 * https://pubs.opengroup.org/onlinepubs/9799919799/functions/setrlimit.html
 */

#include <stdio.h>
#include <stdlib.h>

#define BUFSIZK	4

int
main(int argc, char **argv)
{
  int i;
  int *buf;

  /*
   * Limit to 4 GB, to avoid problems if memory limits are not
   * working as expected.
   */
  for (i = 0; i < (4 * 1024 * 1024) / BUFSIZK; i++) {
    /* Allocate, write to force a page, and discard. */
    buf = malloc(BUFSIZK * 1024);
    if (buf == NULL)
      break;
    buf[0] = 0;
    buf = NULL;
  }

  /* Print in kB. */
  printf("%d\n", i * BUFSIZK);
}