1cc290419Sopenharmony_ci/*
2cc290419Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3cc290419Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cc290419Sopenharmony_ci * you may not use this file except in compliance with the License.
5cc290419Sopenharmony_ci * You may obtain a copy of the License at
6cc290419Sopenharmony_ci *
7cc290419Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cc290419Sopenharmony_ci *
9cc290419Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cc290419Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cc290419Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cc290419Sopenharmony_ci * See the License for the specific language governing permissions and
13cc290419Sopenharmony_ci * limitations under the License.
14cc290419Sopenharmony_ci */
15cc290419Sopenharmony_ci//! sendmsg
16cc290419Sopenharmony_ci#![allow(missing_docs)]
17cc290419Sopenharmony_ci#[cfg(not(target_os = "windows"))]
18cc290419Sopenharmony_ciuse std::ffi::c_int;
19cc290419Sopenharmony_ci
20cc290419Sopenharmony_ci#[cfg(not(target_os = "windows"))]
21cc290419Sopenharmony_ciextern "C" {
22cc290419Sopenharmony_ci    fn SendMsg(socket_fd: c_int, fd: c_int, data: *mut libc::c_char, size: c_int) -> c_int;
23cc290419Sopenharmony_ci}
24cc290419Sopenharmony_ci
25cc290419Sopenharmony_ci#[cfg(not(target_os = "windows"))]
26cc290419Sopenharmony_cipub fn send_msg(socket_fd: i32, fd: i32, data: &[u8]) -> i32 {
27cc290419Sopenharmony_ci    unsafe {
28cc290419Sopenharmony_ci        SendMsg(
29cc290419Sopenharmony_ci            socket_fd,
30cc290419Sopenharmony_ci            fd,
31cc290419Sopenharmony_ci            data.as_ptr() as *mut libc::c_char,
32cc290419Sopenharmony_ci            data.len() as i32,
33cc290419Sopenharmony_ci        )
34cc290419Sopenharmony_ci    }
35cc290419Sopenharmony_ci}
36