From fb5b49c0a20aad15b437a6040a6626047a2df657 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter@cassini.intern> Date: Mon, 11 Jan 2016 16:39:17 +0100 Subject: [PATCH] Praktikum 11.1.2016: Beispielprogramme --- 20160111/noreturn-1.c | 13 +++++++++++++ 20160111/random-1.c | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 20160111/noreturn-1.c create mode 100644 20160111/random-1.c diff --git a/20160111/noreturn-1.c b/20160111/noreturn-1.c new file mode 100644 index 0000000..36bba51 --- /dev/null +++ b/20160111/noreturn-1.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> + +__attribute__ ((noreturn)) void fatal_error (char *msg) +{ + fprintf (stderr, "%s\n", msg); + exit (1); +} + +int main (void) +{ + fatal_error ("error not found"); +} diff --git a/20160111/random-1.c b/20160111/random-1.c new file mode 100644 index 0000000..5b72b6b --- /dev/null +++ b/20160111/random-1.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +int main (int argc, char **argv) +{ + FILE *dev_random = fopen ("/dev/random", "rb"); + if (!dev_random) + { + fprintf (stderr, "%s: cannot open /dev/random\n", argv[0]); + exit (1); + } + else + { + uint16_t x; + fread (&x, sizeof (x), 1, dev_random); + printf ("%d\n", x); + fclose (dev_random); + } + return 0; +} -- GitLab