#ifndef PROGRAMS_PROG_UTIL_H
#define PROGRAMS_PROG_UTIL_H
#ifdef _WIN32
# undef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE 1
# undef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS 1
#else
# undef _FILE_OFFSET_BITS
# define _FILE_OFFSET_BITS 64
# if defined(__linux__)
# undef _GNU_SOURCE
# define _GNU_SOURCE
# undef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200809L
# elif defined(__APPLE__)
# undef _DARWIN_C_SOURCE
# define _DARWIN_C_SOURCE
# undef _POSIX_C_SOURCE
# elif defined(__sun)
# undef __EXTENSIONS__
# define __EXTENSIONS__
# undef _POSIX_C_SOURCE
# else
# undef _POSIX_C_SOURCE
# endif
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "../common_defs.h"
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WIN32
# include <sys/types.h>
#endif
#if defined(__GNUC__) || __has_attribute(format)
# define _printf(str_idx, args_idx) \
__attribute__((format(printf, str_idx, args_idx)))
#else
# define _printf(str_idx, args_idx)
#endif
#ifdef _WIN32
#include <io.h>
#include <wchar.h>
int wmain(int argc, wchar_t **argv);
# define tmain wmain
# define tchar wchar_t
# define _T(text) L##text
# define T(text) _T(text)
# define TS "ls"
# define TC "lc"
# define tmemcpy wmemcpy
# define topen _wopen
# define tstrchr wcschr
# define tstrcmp wcscmp
# define tstrlen wcslen
# define tstrrchr wcsrchr
# define tstrtoul wcstoul
# define tstrxcmp wcsicmp
# define tunlink _wunlink
# define tutimbuf __utimbuf64
# define tutime _wutime64
# define tstat _wstat64
# define tfstat _fstat64
# define stat_t struct _stat64
# ifdef _MSC_VER
# define STDIN_FILENO 0
# define STDOUT_FILENO 1
# define STDERR_FILENO 2
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# endif
#else
# define tmain main
# define tchar char
# define T(text) text
# define TS "s"
# define TC "c"
# define tmemcpy memcpy
# define topen open
# define tstrchr strchr
# define tstrcmp strcmp
# define tstrlen strlen
# define tstrrchr strrchr
# define tstrtoul strtoul
# define tstrxcmp strcmp
# define tunlink unlink
# define tutimbuf utimbuf
# define tutime utime
# define tstat stat
# define tfstat fstat
# define stat_t struct stat
#endif
extern const tchar *prog_invocation_name;
extern bool suppress_warnings;
void _printf(1, 2) msg(const char *fmt, ...);
void _printf(1, 2) msg_errno(const char *fmt, ...);
void _printf(1, 2) warn(const char *fmt, ...);
void *xmalloc(size_t size);
void begin_program(tchar *argv[]);
struct file_stream {
int fd;
tchar *name;
bool is_standard_stream;
void *mmap_token;
void *mmap_mem;
size_t mmap_size;
};
int xopen_for_read(const tchar *path, bool symlink_ok,
struct file_stream *strm);
int xopen_for_write(const tchar *path, bool force, struct file_stream *strm);
int map_file_contents(struct file_stream *strm, u64 size);
ssize_t xread(struct file_stream *strm, void *buf, size_t count);
int full_write(struct file_stream *strm, const void *buf, size_t count);
int xclose(struct file_stream *strm);
int parse_compression_level(tchar opt_char, const tchar *arg);
struct libdeflate_compressor *alloc_compressor(int level);
struct libdeflate_decompressor *alloc_decompressor(void);
extern tchar *toptarg;
extern int toptind, topterr, toptopt;
int tgetopt(int argc, tchar *argv[], const tchar *optstring);
#endif