summaryrefslogtreecommitdiff
path: root/src/random/generate-random.c
blob: 955fb88fa927661af17ccc124106e538c5c6baaa (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
  webid-oidc, implementation of the Solid specification
  Copyright (C) 2020, 2021  Vivien Kraus

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#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;
}