starnix_uapi/
syslog.rs

1// Copyright 2023 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::error;
6use crate::errors::Errno;
7
8// See "The symbolic names are defined in the kernel source, but are
9// not exported to user space; you will either need to use the numbers,
10// or define the names yourself" at syslog(2).
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum SyslogAction {
13    Close = 0,
14    Open = 1,
15    Read = 2,
16    ReadAll = 3,
17    ReadClear = 4,
18    Clear = 5,
19    ConsoleOff = 6,
20    ConsoleOn = 7,
21    ConsoleLevel = 8,
22    SizeUnread = 9,
23    SizeBuffer = 10,
24}
25
26impl TryFrom<i32> for SyslogAction {
27    type Error = Errno;
28    fn try_from(number: i32) -> Result<SyslogAction, Self::Error> {
29        match number {
30            0 => Ok(Self::Close),
31            1 => Ok(Self::Open),
32            2 => Ok(Self::Read),
33            3 => Ok(Self::ReadAll),
34            4 => Ok(Self::ReadClear),
35            5 => Ok(Self::Clear),
36            6 => Ok(Self::ConsoleOff),
37            7 => Ok(Self::ConsoleOn),
38            8 => Ok(Self::ConsoleLevel),
39            9 => Ok(Self::SizeUnread),
40            10 => Ok(Self::SizeBuffer),
41            _ => return error!(EINVAL),
42        }
43    }
44}