/src/sudo/lib/iolog/iolog_util.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright (c) 2009-2021 Todd C. Miller <Todd.Miller@sudo.ws> |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | */ |
18 | | |
19 | | /* |
20 | | * This is an open source non-commercial project. Dear PVS-Studio, please check it. |
21 | | * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com |
22 | | */ |
23 | | |
24 | | #include <config.h> |
25 | | |
26 | | #include <stdio.h> |
27 | | #include <stdlib.h> |
28 | | #ifdef HAVE_STDBOOL_H |
29 | | # include <stdbool.h> |
30 | | #else |
31 | | # include "compat/stdbool.h" |
32 | | #endif |
33 | | #include <time.h> |
34 | | |
35 | | #include "sudo_compat.h" |
36 | | #include "sudo_debug.h" |
37 | | #include "sudo_iolog.h" |
38 | | |
39 | | /* |
40 | | * Map IOFD_* -> name. |
41 | | */ |
42 | | const char * |
43 | | iolog_fd_to_name(int iofd) |
44 | 843 | { |
45 | 843 | const char *ret; |
46 | 843 | debug_decl(iolog_fd_to_name, SUDO_DEBUG_UTIL); |
47 | | |
48 | 843 | switch (iofd) { |
49 | 0 | case IOFD_STDIN: |
50 | 0 | ret = "stdin"; |
51 | 0 | break; |
52 | 0 | case IOFD_STDOUT: |
53 | 0 | ret = "stdout"; |
54 | 0 | break; |
55 | 0 | case IOFD_STDERR: |
56 | 0 | ret = "stderr"; |
57 | 0 | break; |
58 | 0 | case IOFD_TTYIN: |
59 | 0 | ret = "ttyin"; |
60 | 0 | break; |
61 | 0 | case IOFD_TTYOUT: |
62 | 0 | ret = "ttyout"; |
63 | 0 | break; |
64 | 843 | case IOFD_TIMING: |
65 | 843 | ret = "timing"; |
66 | 843 | break; |
67 | 0 | default: |
68 | 0 | ret = "unknown"; |
69 | 0 | sudo_debug_printf(SUDO_DEBUG_ERROR, "%s: unexpected iofd %d", |
70 | 0 | __func__, iofd); |
71 | 0 | break; |
72 | 843 | } |
73 | 843 | debug_return_const_str(ret); |
74 | 843 | } |