openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/dbus/1.12.16-r0/dbus-1.12.16/dbus/dbus-sysdeps-unix.c
dbus_bool_t _dbus_generate_random_bytes(DBusString* str, int n_bytes,
                                        DBusError* error)
{
    int old_len;
    int fd;
    int result;

    old_len = _dbus_string_get_length(str);
    fd = -1;

    /* note, urandom on linux will fall back to pseudorandom */
    fd = open("/dev/urandom", O_RDONLY);

    if (fd < 0)
    {
        dbus_set_error(error, _dbus_error_from_errno(errno),
                       "Could not open /dev/urandom: %s",
                       _dbus_strerror(errno));
        return FALSE;
    }

    _dbus_verbose("/dev/urandom fd %d opened\n", fd);

    result = _dbus_read(fd, str, n_bytes);

    if (result != n_bytes)
    {
        if (result < 0)
            dbus_set_error(error, _dbus_error_from_errno(errno),
                           "Could not read /dev/urandom: %s",
                           _dbus_strerror(errno));
        else
            dbus_set_error(error, DBUS_ERROR_IO_ERROR,
                           "Short read from /dev/urandom");

        _dbus_close(fd, NULL);
        _dbus_string_set_length(str, old_len);
        return FALSE;
    }

    _dbus_verbose("Read %d bytes from /dev/urandom\n", n_bytes);

    _dbus_close(fd, NULL);

    return TRUE;
}
/**
 * Generates the given number of securely random bytes,
 * using the best mechanism we can come up with.
 *
 * @param str the string
 * @param n_bytes the number of random bytes to append to string
 * @param error location to store reason for failure
 * @returns #TRUE on success, #FALSE on error
 */
Generates the given number of securely random bytes,
using the best mechanism we can come up with.

@param str the string
@param n_bytes the number of random bytes to append to string
@param error location to store reason for failure
@returns #TRUE on success, #FALSE on error
Generates the given number of securely random bytes using the best mechanism we can come up with . @param str the string @param n_bytes the number of random bytes to append to string @param error location to store reason for failure @returns #TRUE on success #FALSE on error
dbus_bool_t _dbus_generate_random_bytes(DBusString* str, int n_bytes,
                                        DBusError* error)
{
    int old_len;
    int fd;
    int result;
    old_len = _dbus_string_get_length(str);
    fd = -1;
    fd = open("/dev/urandom", O_RDONLY);
    if (fd < 0)
    {
        dbus_set_error(error, _dbus_error_from_errno(errno),
                       "Could not open /dev/urandom: %s",
                       _dbus_strerror(errno));
        return FALSE;
    }
    _dbus_verbose("/dev/urandom fd %d opened\n", fd);
    result = _dbus_read(fd, str, n_bytes);
    if (result != n_bytes)
    {
        if (result < 0)
            dbus_set_error(error, _dbus_error_from_errno(errno),
                           "Could not read /dev/urandom: %s",
                           _dbus_strerror(errno));
        else
            dbus_set_error(error, DBUS_ERROR_IO_ERROR,
                           "Short read from /dev/urandom");
        _dbus_close(fd, NULL);
        _dbus_string_set_length(str, old_len);
        return FALSE;
    }
    _dbus_verbose("Read %d bytes from /dev/urandom\n", n_bytes);
    _dbus_close(fd, NULL);
    return TRUE;
}
dbus_bool_t _dbus_generate_random_bytes ( DBusString * str , int n_bytes , DBusError * error ) { int old_len ; int fd ; int result ; old_len = _dbus_string_get_length ( str ) ; fd = -1 ; fd = open ( " " , O_RDONLY ) ; if ( fd < 0 ) { dbus_set_error ( error , _dbus_error_from_errno ( errno ) , " " , _dbus_strerror ( errno ) ) ; return FALSE ; } _dbus_verbose ( " \n " , fd ) ; result = _dbus_read ( fd , str , n_bytes ) ; if ( result != n_bytes ) { if ( result < 0 ) dbus_set_error ( error , _dbus_error_from_errno ( errno ) , " " , _dbus_strerror ( errno ) ) ; else dbus_set_error ( error , DBUS_ERROR_IO_ERROR , " " ) ; _dbus_close ( fd , NULL ) ; _dbus_string_set_length ( str , old_len ) ; return FALSE ; } _dbus_verbose ( " \n " , n_bytes ) ; _dbus_close ( fd , NULL ) ; return TRUE ; }
Generates the given number of securely random bytes,
 using the best mechanism we can come up with.
Generates the given number of securely random bytes using the best mechanism we can come up with .
/* note, urandom on linux will fall back to pseudorandom */