xref: /freebsd/contrib/xz/src/xz/private.h (revision 128836d304d93f2d00eb14069c27089ab46c38d4)
1 // SPDX-License-Identifier: 0BSD
2 
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       private.h
6 /// \brief      Common includes, definitions, and prototypes
7 //
8 //  Author:     Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
11 
12 #include "sysdefs.h"
13 #include "mythread.h"
14 
15 #include "lzma.h"
16 
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <errno.h>
20 #include <signal.h>
21 #include <locale.h>
22 #include <stdio.h>
23 
24 #ifndef _MSC_VER
25 #	include <unistd.h>
26 #endif
27 
28 #include "tuklib_gettext.h"
29 #include "tuklib_progname.h"
30 #include "tuklib_exit.h"
31 #include "tuklib_mbstr_nonprint.h"
32 #include "tuklib_mbstr.h"
33 
34 #if defined(_WIN32) && !defined(__CYGWIN__)
35 #	define WIN32_LEAN_AND_MEAN
36 #	include <windows.h>
37 #endif
38 
39 #ifdef _MSC_VER
40 #	define fileno _fileno
41 #endif
42 
43 #ifndef STDIN_FILENO
44 #	define STDIN_FILENO (fileno(stdin))
45 #endif
46 
47 #ifndef STDOUT_FILENO
48 #	define STDOUT_FILENO (fileno(stdout))
49 #endif
50 
51 #ifndef STDERR_FILENO
52 #	define STDERR_FILENO (fileno(stderr))
53 #endif
54 
55 // Handling SIGTSTP keeps time-keeping for progress indicator correct
56 // if xz is stopped. It requires use of clock_gettime() as that is
57 // async-signal safe in POSIX. Require also SIGALRM support since
58 // on systems where SIGALRM isn't available, progress indicator code
59 // polls the time and the SIGTSTP handling adds slight overhead to
60 // that code. Most (all?) systems that have SIGTSTP also have SIGALRM
61 // so this requirement won't exclude many systems.
62 #if defined(HAVE_CLOCK_GETTIME) && defined(SIGTSTP) && defined(SIGALRM)
63 #	define USE_SIGTSTP_HANDLER 1
64 #endif
65 
66 #include "main.h"
67 #include "mytime.h"
68 #include "coder.h"
69 #include "message.h"
70 #include "args.h"
71 #include "hardware.h"
72 #include "file_io.h"
73 #include "options.h"
74 #include "sandbox.h"
75 #include "signals.h"
76 #include "suffix.h"
77 #include "util.h"
78 
79 #ifdef HAVE_DECODERS
80 #	include "list.h"
81 #endif
82