VirtualBox

Changeset 100037 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Jun 1, 2023 6:06:11 PM (20 months ago)
Author:
vboxsync
Message:

Runtime/RTFdt: Add methods to add stringlist properties, bugref:10401

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/fdt.cpp

    r100036 r100037  
    15821582    return VINF_SUCCESS;
    15831583}
     1584
     1585
     1586RTDECL(int) RTFdtNodePropertyAddStringList(RTFDT hFdt, const char *pszProperty, uint32_t cStrings, ...)
     1587{
     1588    va_list va;
     1589    va_start(va, cStrings);
     1590    int rc = RTFdtNodePropertyAddStringListV(hFdt, pszProperty, cStrings, va);
     1591    va_end(va);
     1592    return rc;
     1593}
     1594
     1595
     1596RTDECL(int) RTFdtNodePropertyAddStringListV(RTFDT hFdt, const char *pszProperty, uint32_t cStrings, va_list va)
     1597{
     1598    PRTFDTINT pThis = hFdt;
     1599    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1600
     1601    /* Insert the property name into the strings block. */
     1602    uint32_t offStr;
     1603    int rc = rtFdtStringsInsertString(pThis, pszProperty, &offStr);
     1604    if (RT_FAILURE(rc))
     1605        return rc;
     1606
     1607    va_list vaCopy;
     1608    va_copy(vaCopy, va);
     1609
     1610    /* First pass, go over all strings and find out how much we have to add in total. */
     1611    uint32_t cbStrings = 0;
     1612    for (uint32_t i = 0; i < cStrings; i++)
     1613        cbStrings += strlen(va_arg(vaCopy, const char *)) + 1; /* Include terminator. */
     1614
     1615    uint32_t cbProp = RT_ALIGN_32(cbStrings + 3 * sizeof(uint32_t), sizeof(uint32_t)); /* Account for property token and the property data. */
     1616    rc = rtFdtStructEnsureSpace(pThis, cbProp);
     1617    if (RT_FAILURE(rc))
     1618        return rc;
     1619
     1620    /* Add the data. */
     1621    uint32_t *pu32 = (uint32_t *)(pThis->pbStruct + pThis->cbStruct);
     1622    *pu32++ = DTB_FDT_TOKEN_PROPERTY_BE;
     1623    *pu32++ = RT_H2BE_U32(cbStrings);
     1624    *pu32++ = RT_H2BE_U32(offStr);
     1625
     1626    char *pb = (char *)pu32;
     1627    for (uint32_t i = 0; i < cStrings; i++)
     1628        pb = stpcpy(pb, va_arg(va, const char *)) + 1;
     1629
     1630    pThis->cbStruct += cbProp;
     1631    return VINF_SUCCESS;
     1632}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette