1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
15 #include <oslrandom.h>
17 int osl_get_system_random_data(char* buffer
, size_t desired_len
)
21 /* if unaligned fill to alignment */
22 if (reinterpret_cast<uintptr_t>(buffer
) & 3)
24 size_t len
= 4 - (reinterpret_cast<size_t>(buffer
) & 3);
26 if (len
> desired_len
)
34 memcpy(buffer
, &val
, len
);
38 /* fill directly into the buffer as long as we can */
39 while (desired_len
>= 4)
41 if (rand_s(reinterpret_cast<unsigned int*>(buffer
)))
51 /* deal with the partial int reminder to fill */
58 memcpy(buffer
, &val
, desired_len
);
63 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */