• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2025, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! This module provides printing back-end functions to be used by GBL format
16 //! printing implementation: libc/src/print.c
17 
18 use crate::gbl_print;
19 use core::ffi::{c_char, CStr};
20 
21 /// Back-end function to print a nul-terminated string.
22 ///
23 /// # Safety:
24 ///
25 /// * `s` must be a valid null-terminated C string.
26 #[no_mangle]
gbl_print_string(s: *const c_char)27 pub unsafe extern "C" fn gbl_print_string(s: *const c_char) {
28     if s.is_null() {
29         return;
30     }
31     // SAFETY: `s` must be a valid nul-terminated C string.
32     let cstr = unsafe { CStr::from_ptr(s) };
33 
34     // Safety:
35     // * `gbl_print` is expected to be statically linked and expected
36     // core::fmt::Display compatible types.
37     unsafe {
38         gbl_print(&cstr.to_string_lossy());
39     }
40 }
41