---
name: "hwloc_export_obj_userdata"
section: "3"
platform: "linux"
package: "hwloc"
version: "2.15.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/hwlocality_xmlexport"
---

# hwloc\_export\_obj\_userdata(3)

Exporting Topologies to XML

Part of [hwlocality\_xmlexport(3)](/hwlocality_xmlexport/3.md).

## NAME

hwlocality\_xmlexport - Exporting Topologies to XML

## SYNOPSIS

### Enumerations

enum **hwloc\_topology\_export\_xml\_flags\_e** { **HWLOC\_TOPOLOGY\_EXPORT\_XML\_FLAG\_V1** }\

### Functions

int **hwloc\_topology\_export\_xml** (**hwloc\_topology\_t** topology, const char \*xmlpath, unsigned long flags)\
 int **hwloc\_topology\_export\_xmlbuffer** (**hwloc\_topology\_t** topology, char \*\*xmlbuffer, int \*buflen, unsigned long flags)\
 void **hwloc\_free\_xmlbuffer** (**hwloc\_topology\_t** topology, char \*xmlbuffer)\
 void **hwloc\_topology\_set\_userdata\_export\_callback** (**hwloc\_topology\_t** topology, void(\*export\_cb)(void \*reserved, **hwloc\_topology\_t** topology, **hwloc\_obj\_t** obj))\
 int **hwloc\_export\_obj\_userdata** (void \*reserved, **hwloc\_topology\_t** topology, **hwloc\_obj\_t** obj, const char \*name, const void \*buffer, size\_t length)\
 int **hwloc\_export\_obj\_userdata\_base64** (void \*reserved, **hwloc\_topology\_t** topology, **hwloc\_obj\_t** obj, const char \*name, const void \*buffer, size\_t length)\
 void **hwloc\_topology\_set\_userdata\_import\_callback** (**hwloc\_topology\_t** topology, void(\*import\_cb)(**hwloc\_topology\_t** topology, **hwloc\_obj\_t** obj, const char \*name, const void \*buffer, size\_t length))\

## Detailed Description

## Enumeration Type Documentation

### enum hwloc\_topology\_export\_xml\_flags\_e

Flags for exporting XML topologies. Flags to be given as a OR'ed set to **hwloc\_topology\_export\_xml()**.

**Enumerator**

- ***HWLOC\_TOPOLOGY\_EXPORT\_XML\_FLAG\_V1***

  Export XML that is loadable by hwloc v1.x. However, the export may miss some details about the topology.

## Function Documentation

### int hwloc\_export\_obj\_userdata (void \* reserved, hwloc\_topology\_t topology, hwloc\_obj\_t obj, const char \* name, const void \* buffer, size\_t length)

Export some object userdata to XML. This function may only be called from within the export() callback passed to **hwloc\_topology\_set\_userdata\_export\_callback()**. It may be invoked one of multiple times to export some userdata to XML. The buffer content of length length is stored with optional name name.

When importing this XML file, the import() callback (if set) will be called exactly as many times as **hwloc\_export\_obj\_userdata()** was called during export(). It will receive the corresponding name, buffer and length arguments.

reserved, topology and obj must be the first three parameters that were given to the export callback.

Only printable characters may be exported to XML string attributes.

If exporting binary data, the application should first encode into printable characters only (or use **hwloc\_export\_obj\_userdata\_base64()**). It should also take care of portability issues if the export may be reimported on a different architecture.

**Returns**

0 on success.

\-1 with errno set to EINVAL if a non-printable character is passed in name or **buffer**.

### int hwloc\_export\_obj\_userdata\_base64 (void \* reserved, hwloc\_topology\_t topology, hwloc\_obj\_t obj, const char \* name, const void \* buffer, size\_t length)

Encode and export some object userdata to XML. This function is similar to **hwloc\_export\_obj\_userdata()** but it encodes the input buffer into printable characters before exporting. On import, decoding is automatically performed before the data is given to the import() callback if any.

This function may only be called from within the export() callback passed to **hwloc\_topology\_set\_userdata\_export\_callback()**.

The name must be made of printable characters for export to XML string attributes.

The function does not take care of portability issues if the export may be reimported on a different architecture.

**Returns**

0 on success.

\-1 with errno set to EINVAL if a non-printable character is passed in name.

### void hwloc\_free\_xmlbuffer (hwloc\_topology\_t topology, char \* xmlbuffer)

Free a buffer allocated by **hwloc\_topology\_export\_xmlbuffer()**.

### int hwloc\_topology\_export\_xml (hwloc\_topology\_t topology, const char \* xmlpath, unsigned long flags)

Export the topology into an XML file. This file may be loaded later through **hwloc\_topology\_set\_xml()**.

By default, the latest export format is used, which means older hwloc releases (e.g. v1.x) will not be able to import it. Exporting to v1.x specific XML format is possible using flag **HWLOC\_TOPOLOGY\_EXPORT\_XML\_FLAG\_V1** but it may miss some details about the topology. If there is any chance that the exported file may ever be imported back by a process using hwloc 1.x, one should consider detecting it at runtime and using the corresponding export format.

flags is a OR'ed set of **hwloc\_topology\_export\_xml\_flags\_e**.

**Returns**

0 on success, or -1 on error.

**Note**

See also **hwloc\_topology\_set\_userdata\_export\_callback()** for exporting application-specific object userdata.

The topology-specific userdata pointer is ignored when exporting to XML.

Only printable characters may be exported to XML string attributes. Any other character, especially any non-ASCII character, will be silently dropped.

If name is "-", the XML output is sent to the standard output.

### int hwloc\_topology\_export\_xmlbuffer (hwloc\_topology\_t topology, char \*\* xmlbuffer, int \* buflen, unsigned long flags)

Export the topology into a newly-allocated XML memory buffer. xmlbuffer is allocated by the callee and should be freed with **hwloc\_free\_xmlbuffer()** later in the caller.

This memory buffer may be loaded later through **hwloc\_topology\_set\_xmlbuffer()**.

By default, the latest export format is used, which means older hwloc releases (e.g. v1.x) will not be able to import it. Exporting to v1.x specific XML format is possible using flag **HWLOC\_TOPOLOGY\_EXPORT\_XML\_FLAG\_V1** but it may miss some details about the topology. If there is any chance that the exported buffer may ever be imported back by a process using hwloc 1.x, one should consider detecting it at runtime and using the corresponding export format.

The returned buffer ends with a \\0 that is included in the returned length.

flags is a OR'ed set of **hwloc\_topology\_export\_xml\_flags\_e**.

**Returns**

0 on success, or -1 on error.

**Note**

See also **hwloc\_topology\_set\_userdata\_export\_callback()** for exporting application-specific object userdata.

The topology-specific userdata pointer is ignored when exporting to XML.

Only printable characters may be exported to XML string attributes. Any other character, especially any non-ASCII character, will be silently dropped.

### void hwloc\_topology\_set\_userdata\_export\_callback (hwloc\_topology\_t topology, void(\* export\_cb )(void \*reserved, hwloc\_topology\_t topology, hwloc\_obj\_t obj))

Set the application-specific callback for exporting object userdata. The object userdata pointer is not exported to XML by default because hwloc does not know what it contains.

This function lets applications set export\_cb to a callback function that converts this opaque userdata into an exportable string.

export\_cb is invoked during XML export for each object whose userdata pointer is not NULL. The callback should use **hwloc\_export\_obj\_userdata()** or **hwloc\_export\_obj\_userdata\_base64()** to actually export something to XML (possibly multiple times per object).

export\_cb may be set to NULL if userdata should not be exported to XML.

**Note**

The topology-specific userdata pointer is ignored when exporting to XML.

### void hwloc\_topology\_set\_userdata\_import\_callback (hwloc\_topology\_t topology, void(\* import\_cb )(hwloc\_topology\_t topology, hwloc\_obj\_t obj, const char \*name, const void \*buffer, size\_t length))

Set the application-specific callback for importing userdata. On XML import, userdata is ignored by default because hwloc does not know how to store it in memory.

This function lets applications set import\_cb to a callback function that will get the XML-stored userdata and store it in the object as expected by the application.

import\_cb is called during **hwloc\_topology\_load()** as many times as **hwloc\_export\_obj\_userdata()** was called during export. The topology is not entirely setup yet. Object attributes are ready to consult, but links between objects are not.

import\_cb may be NULL if userdata should be ignored during import.

**Note**

buffer contains length characters followed by a null byte ('\\0').

This function should be called before **hwloc\_topology\_load()**.

The topology-specific userdata pointer is ignored when importing from XML.

## Author

Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.
