1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5
6 /*
7 WARNING: This file was generated by the dkct program (see
8 http://dktools.sourceforge.net/ for details).
9 Changes you make here will be lost if dkct is run again!
10 You should modify the original source and run dkct on it.
11 Original source: dk4istty.ctr
12 */
13
14 /** @file dk4istty.c The dk4istty module.
15 */
16
17
18 #include "dk4conf.h"
19 #include <libdk4c/dk4istty.h>
20
21 #if DK4_HAVE_UNISTD_H
22 #ifndef UNISTD_H_INCLUDED
23 #include <unistd.h>
24 #define UNISTD_H_INCLUDED 1
25 #endif
26 #endif
27
28 #if DK4_HAVE_IO_H
29 #ifndef IO_H_INCLUDED
30 #include <io.h>
31 #define IO_H_INCLUDED 1
32 #endif
33 #endif
34
35 #if DK4_HAVE_ASSERT_H
36 #ifndef ASSERT_H_INCLUDED
37 #include <assert.h>
38 #define ASSERT_H_INCLUDED 1
39 #endif
40 #endif
41
42 #include <libdk4base/dk4unused.h>
43
44
45
46
47
48
49
50 int
dk4istty(int fd,dk4_er_t * DK4_ARG_UNUSED (erp))51 dk4istty(
52 #if (DK4_HAVE_ISATTY) || (DK4_HAVE__ISATTY)
53 int fd, dk4_er_t * DK4_ARG_UNUSED(erp)
54 #else
55 int fd, dk4_er_t *erp
56 #endif
57 )
58 {
59 int back = -1;
60 #if DK4_HAVE_ISATTY
61 DK4_UNUSED_ARG(erp)
62 if ( 0 != isatty(fd) ) {
63 back = 1;
64 } else {
65 back = 0;
66 }
67 #else
68 #if DK4_HAVE__ISATTY
69 DK4_UNUSED_ARG(erp)
70 if ( 0 != _isatty(fd) ) {
71 back = 1;
72 } else {
73 back = 0;
74 }
75 #else
76 dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
77 #endif
78 #endif
79 return back;
80 }
81
82
83
84 int
dk4istty_file(FILE * fipo,dk4_er_t * erp)85 dk4istty_file(FILE *fipo, dk4_er_t *erp)
86 {
87 int back = -1;
88 #if DK4_USE_ASSERT
89 assert(NULL != fipo);
90 #endif
91 if (NULL != fipo) {
92 #if DK4_HAVE_FILENO
93 back = dk4istty(fileno(fipo), erp);
94 #else
95 #if DK4_HAVE__FILENO
96 back = dk4istty(_fileno(fipo), erp);
97 #else
98 dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
99 #endif
100 #endif
101 } else {
102 dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
103 }
104 return back;
105 }
106
107
108