| 1 |
/* |
| 2 |
* SPDX-License-Identifier: BSD-3-Clause |
| 3 |
* Copyright © 2009 CNRS |
| 4 |
* Copyright © 2009-2017 Inria. All rights reserved. |
| 5 |
* Copyright © 2009 Université Bordeaux |
| 6 |
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. |
| 7 |
* See COPYING in top-level directory. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "private/autogen/config.h" |
| 11 |
#include "hwloc.h" |
| 12 |
|
| 13 |
#include <string.h> |
| 14 |
#include <sys/stat.h> |
| 15 |
|
| 16 |
#include "lstopo.h" |
| 17 |
|
| 18 |
int |
| 19 |
output_xml(struct lstopo_output *loutput, const char *filename) |
| 20 |
{ |
| 21 |
struct stat st; |
| 22 |
|
| 23 |
if (!filename || !strcasecmp(filename, "-.xml")) |
| 24 |
filename = "-"; |
| 25 |
/* hwloc_topology_export_xml() writes to stdout if "-" is given */ |
| 26 |
|
| 27 |
if (strcmp(filename, "-") && !stat(filename, &st) && !loutput->overwrite) { |
| 28 |
fprintf(stderr, "Failed to export XML to %s (%s)\n", filename, strerror(EEXIST)); |
| 29 |
return -1; |
| 30 |
} |
| 31 |
|
| 32 |
if (hwloc_topology_export_xml(loutput->topology, filename, loutput->export_xml_flags) < 0) { |
| 33 |
fprintf(stderr, "Failed to export XML to %s (%s)\n", filename, strerror(errno)); |
| 34 |
return -1; |
| 35 |
} |
| 36 |
|
| 37 |
return 0; |
| 38 |
} |