blob: d2344e5e31489a6e92775b1bb03d47415b503f25 [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <errno.h>
#include <fidl/fuchsia.device/cpp/wire.h>
#include <string.h>
#include <sys/utsname.h>
#include <zircon/types.h>
#include <vector>
#include "sdk/lib/fdio/fdio_unistd.h"
#include "sdk/lib/fdio/get_client.h"
extern "C" __EXPORT int uname(utsname* uts) {
if (!uts) {
// Avoid overwriting caller's memory until after all fallible operations have succeeded.
auto& name_provider = get_client<fuchsia_device::NameProvider>();
if (name_provider.is_error()) {
return ERROR(name_provider.status_value());
auto response = name_provider->GetDeviceName();
if (response.status() != ZX_OK) {
return ERROR(response.status());
auto* result = response.Unwrap();
if (result->is_error()) {
return ERROR(result->error_value());
const fidl::StringView& nodename = result->value()->name;
const auto size = std::min(nodename.size(), sizeof(uts->nodename) - 1);
memcpy(uts->nodename,, size);
uts->nodename[size] = '\0';
strcpy(uts->sysname, "Fuchsia");
strcpy(uts->release, "");
strcpy(uts->version, "");
#if defined(__x86_64__)
strcpy(uts->machine, "x86_64");
#elif defined(__aarch64__)
strcpy(uts->machine, "aarch64");
strcpy(uts->machine, "");
#ifdef _GNU_SOURCE
strcpy(uts->domainname, "");
strcpy(uts->__domainname, "");
return 0;