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/.
10 #if !defined _CRT_RAND_S
17 #include <oslrandom.h>
19 int osl_get_system_random_data(char* buffer
, size_t desired_len
)
23 /* if unaligned fill to alignment */
24 if(reinterpret_cast<uintptr_t>(buffer
) & 3)
26 size_t len
= 4 - (reinterpret_cast<size_t>(buffer
) & 3);
36 memcpy(buffer
, &val
, len
);
40 /* fill directly into the buffer as long as we can */
41 while(desired_len
>= 4)
43 if(rand_s(reinterpret_cast<unsigned int*>(buffer
)))
53 /* deal with the partial int reminder to fill */
60 memcpy(buffer
, &val
, desired_len
);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */