summaryrefslogtreecommitdiff
path: root/src/random/generate-random.c
blob: bde01b906decf119590b75a01d8603aca22f6e99 (plain)
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
37
38
39
40
41
42
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */

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

#define _(s) gettext (s)

SCM webidoidc_random_g (SCM length);

int init_webidoidc_random (void);

static void
run (void *params, int argc, char *argv[])
{
  size_t n_bytes;
  char *end;
  SCM data;
  (void) params;
  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
  if (argc != 2
      || (n_bytes = strtoull (argv[1], &end, 10)) == 0 || *end != '\0')
    {
      fprintf (stderr, _("Usage: generate-random [NUMBER OF BYTES]\n"));
      exit (1);
    }
  init_webidoidc_random ();
  data = webidoidc_random_g (scm_from_size_t (n_bytes));
  printf ("%s\n", scm_to_locale_string (data));
}

int
main (int argc, char *argv[])
{
  scm_boot_guile (argc, argv, run, NULL);
  return 0;
}