Skip to main content

rust_libc_tests/
rust-libc-tests.rs

1// Copyright 2026 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7#![no_std]
8#![allow(clippy::write_literal)]
9
10use core::fmt::Write as _;
11use core::write;
12use libc::stdio::FILE;
13
14#[unsafe(no_mangle)]
15pub extern "C" fn write_to_stdio_in_rust(f: &mut FILE) -> bool {
16    write!(f, "{} {}!", "Hello", "world").is_ok()
17}
18
19#[unsafe(no_mangle)]
20pub extern "C" fn write_to_stdio_with_nul_in_rust(f: &mut FILE) -> bool {
21    write!(f, "{}\0{}!", "Hello", "world").is_ok()
22}