tdf#154546 skip dispatch when presenter controller is not set
[LibreOffice.git] / sal / osl / unx / random.cxx
blob260aa61ba8a47d6b16a6358588c4b4de9b5fa6de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "system.hxx"
11 #include <oslrandom.h>
13 #include <assert.h>
15 int osl_get_system_random_data(char* buffer, size_t desired_len)
17 int fd;
19 assert(buffer);
20 fd = open("/dev/urandom", O_RDONLY);
21 if (fd != -1)
23 while (desired_len)
25 ssize_t nb_read;
26 if ((nb_read = read(fd, buffer, desired_len)) == -1)
28 if (errno != EINTR)
30 close(fd);
31 return false;
34 else
36 buffer += nb_read;
37 desired_len -= nb_read;
40 close(fd);
41 return true;
43 return false;
46 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */