Here DOS-like means DOS, Windows, and OS/2.
# include <windows.h>
#endif
+#ifdef __DJGPP__
+# include <dpmi.h>
+#endif
+
/// \brief Get the amount of physical memory in bytes
///
meminfo.dwLength = sizeof(meminfo);
if (GlobalMemoryStatusEx(&meminfo))
ret = meminfo.ullTotalPhys;
+
+#elif defined(__DJGPP__)
+ __dpmi_free_mem_info meminfo;
+ if (__dpmi_get_free_memory_information(&meminfo) == 0
+ && meminfo.total_number_of_physical_pages
+ != (unsigned long)(-1))
+ ret = (uint64_t)(meminfo.total_number_of_physical_pages)
+ * 4096;
#endif
return ret;
// Macros //
////////////
+#if defined(_WIN32) || defined(__MSDOS__) || defined(__OS2__)
+# define DOSLIKE 1
+#endif
+
#undef memzero
#define memzero(s, n) memset(s, 0, n)
* Solaris assembler doesn't have .p2align, and Darwin uses .align
* differently than GNU/Linux and Solaris.
*/
-#ifdef __MACH__
+#if defined(__MACH__) || defined(__MSDOS__)
# define ALIGN(pow2, abs) .align pow2
#else
# define ALIGN(pow2, abs) .align abs
.text
.globl LZMA_CRC32
-#if !defined(__MACH__) && !defined(_WIN32)
+#if !defined(__MACH__) && !defined(_WIN32) && !defined(__MSDOS__)
.type LZMA_CRC32, @function
#endif
.ascii " -export:lzma_crc32"
# endif
-#else
+#elif !defined(__MSDOS__)
/* ELF */
.size LZMA_CRC32, .-LZMA_CRC32
#endif
* Solaris assembler doesn't have .p2align, and Darwin uses .align
* differently than GNU/Linux and Solaris.
*/
-#ifdef __MACH__
+#if defined(__MACH__) || defined(__MSDOS__)
# define ALIGN(pow2, abs) .align pow2
#else
# define ALIGN(pow2, abs) .align abs
.text
.globl LZMA_CRC64
-#if !defined(__MACH__) && !defined(_WIN32)
+#if !defined(__MACH__) && !defined(_WIN32) && !defined(__MSDOS__)
.type LZMA_CRC64, @function
#endif
.ascii " -export:lzma_crc64"
# endif
-#else
+#elif !defined(__MSDOS__)
/* ELF */
.size LZMA_CRC64, .-LZMA_CRC64
#endif
// Check how we were called.
{
- // Remove the leading path name, if any.
-#ifdef _WIN32
- // Some systems support both / and \ to separate path
- // components.
- const char *name = argv[0] + strlen(argv[0]);
- while (argv[0] < name && name[-1] != '/' && name[-1] != '\\')
- --name;
+#ifdef DOSLIKE
+ // We adjusted argv[0] in the beginning of main() so we don't
+ // need to do anything here.
+ const char *name = argv[0];
#else
- // POSIX
+ // Remove the leading path name, if any.
const char *name = strrchr(argv[0], '/');
if (name == NULL)
name = argv[0];
#include <fcntl.h>
+#ifdef DOSLIKE
+# include <io.h>
+#endif
+
#if defined(HAVE_FUTIMES) || defined(HAVE_FUTIMESAT) || defined(HAVE_UTIMES)
# include <sys/time.h>
#elif defined(HAVE_UTIME)
# define O_NOCTTY 0
#endif
-#ifndef _WIN32
+#ifndef DOSLIKE
# include "open_stdxxx.h"
static bool warn_fchown;
#endif
extern void
io_init(void)
{
-#ifndef _WIN32
+#ifndef DOSLIKE
// Make sure that stdin, stdout, and and stderr are connected to
// a valid file descriptor. Exit immediatelly with exit code ERROR
// if we cannot make the file descriptors valid. Maybe we should
warn_fchown = geteuid() == 0;
#endif
+#ifdef __DJGPP__
+ // Avoid doing useless things when statting files.
+ // This isn't important but doesn't hurt.
+ _djstat_flags = _STAT_INODE | _STAT_EXEC_EXT
+ | _STAT_EXEC_MAGIC | _STAT_DIRSIZE;
+#endif
+
return;
}
io_unlink(const char *name, const struct stat *known_st)
{
// On Windows, st_ino is meaningless, so don't bother testing it.
-#ifndef _WIN32
+#ifndef DOSLIKE
struct stat new_st;
if (lstat(name, &new_st)
io_copy_attrs(const file_pair *pair)
{
// Skip chown and chmod on Windows.
-#ifndef _WIN32
+#ifndef DOSLIKE
// This function is more tricky than you may think at first.
// Blindly copying permissions may permit users to access the
// destination file who didn't have permission to access the
// There's nothing to open when reading from stdin.
if (pair->src_name == stdin_filename) {
pair->src_fd = STDIN_FILENO;
-#ifdef _WIN32
+#ifdef DOSLIKE
setmode(STDIN_FILENO, O_BINARY);
#endif
return false;
// Flags for open()
int flags = O_RDONLY | O_BINARY | O_NOCTTY;
-#ifndef _WIN32
+#ifndef DOSLIKE
// If we accept only regular files, we need to be careful to avoid
// problems with special files like devices and FIFOs. O_NONBLOCK
// prevents blocking when opening such files. When we want to accept
#if defined(O_NOFOLLOW)
if (reg_files_only)
flags |= O_NOFOLLOW;
-#elif !defined(_WIN32)
+#elif !defined(DOSLIKE)
// Some POSIX-like systems lack O_NOFOLLOW (it's not required
// by POSIX). Check for symlinks with a separate lstat() on
// these systems.
return true;
}
-#ifndef _WIN32
+#ifndef DOSLIKE
// Drop O_NONBLOCK, which is used only when we are accepting only
// regular files. After the open() call, we want things to block
// instead of giving EAGAIN.
}
// These are meaningless on Windows.
-#ifndef _WIN32
+#ifndef DOSLIKE
if (pair->src_st.st_mode & (S_ISUID | S_ISGID)) {
// gzip rejects setuid and setgid files even
// when --force was used. bzip2 doesn't check
io_close_src(file_pair *pair, bool success)
{
if (pair->src_fd != STDIN_FILENO && pair->src_fd != -1) {
-#ifdef _WIN32
+#ifdef DOSLIKE
(void)close(pair->src_fd);
#endif
// happens to get same inode number, which would make us
// unlink() wrong file.
//
- // NOTE: Windows is an exception to this, because it doesn't
- // allow unlinking files that are open. *sigh*
+ // NOTE: DOS-like systems are an exception to this, because
+ // they don't allow unlinking files that are open. *sigh*
if (success && !opt_keep_original)
io_unlink(pair->src_name, &pair->src_st);
-#ifndef _WIN32
+#ifndef DOSLIKE
(void)close(pair->src_fd);
#endif
}
// We don't modify or free() this.
pair->dest_name = (char *)"(stdout)";
pair->dest_fd = STDOUT_FILENO;
-#ifdef _WIN32
+#ifdef DOSLIKE
setmode(STDOUT_FILENO, O_BINARY);
#endif
return false;
// that stdin, stdout, and stderr are something valid.
io_init();
+#ifdef DOSLIKE
+ // Adjust argv[0] to make it look nicer in messages, and also to
+ // help the code in args.c.
+ {
+ // Strip the leading path.
+ char *p = argv[0] + strlen(argv[0]);
+ while (argv[0] < p && p[-1] != '/' && p[-1] != '\\')
+ --p;
+
+ argv[0] = p;
+
+ // Strip the .exe suffix.
+ p = strrchr(p, '.');
+ if (p != NULL)
+ *p = '\0';
+
+ // Make it lowercase.
+ for (p = argv[0]; *p != '\0'; ++p)
+ if (*p >= 'A' && *p <= 'Z')
+ *p = *p - 'A' + 'a';
+ }
+#endif
+
// Set up the locale.
setlocale(LC_ALL, "");
#ifdef _WIN32
timer_queue = CreateTimerQueue();
#else
+# ifndef SA_RESTART
+# define SA_RESTART 0
+# endif
// Establish the signal handler for SIGALRM. Since this signal
// doesn't require any quick action, we set SA_RESTART.
struct sigaction sa;
#include "private.h"
+// For case-insensitive filename suffix on case-insensitive systems
+#ifdef DOSLIKE
+# define strcmp strcasecmp
+#endif
+
static char *custom_suffix = NULL;
#include <stdio.h>
#include <unistd.h>
-#ifdef _WIN32
+#ifdef DOSLIKE
# include <fcntl.h>
+# include <io.h>
#endif
#include "getopt.h"
lzma_stream strm = LZMA_STREAM_INIT;
// Some systems require setting stdin and stdout to binary mode.
-#ifdef _WIN32
+#ifdef DOSLIKE
setmode(fileno(stdin), O_BINARY);
setmode(fileno(stdout), O_BINARY);
#endif