_WIN32 works with all compilers, while __WIN32__ is MinGW-specific.
This project used __WIN32__ in files that only support MinGW, and _WIN32
in other files such as the library header and example programs. One
place even used WIN32. Avoid this unnecessary complication by just
always using _WIN32.
bool single_tree_only;
};
-#ifdef __WIN32__
+#ifdef _WIN32
extern const struct apply_operations win32_apply_ops;
#else
extern const struct apply_operations unix_apply_ops;
BLOB_IN_NTFS_VOLUME,
#endif
-#ifdef __WIN32__
+#ifdef _WIN32
/* Windows only: the blob's data is available in the file (or named data
* stream) specified by @windows_file. The data might be only properly
* accessible through the Windows API. */
blob_is_in_file(const struct blob_descriptor *blob)
{
return blob->blob_location == BLOB_IN_FILE_ON_DISK
-#ifdef __WIN32__
+#ifdef _WIN32
|| blob->blob_location == BLOB_IN_WINDOWS_FILE
#endif
;
}
-#ifdef __WIN32__
+#ifdef _WIN32
extern const wchar_t *
get_windows_file_path(const struct windows_file *file);
#endif
static inline const tchar *
blob_file_path(const struct blob_descriptor *blob)
{
-#ifdef __WIN32__
+#ifdef _WIN32
if (blob->blob_location == BLOB_IN_WINDOWS_FILE)
return get_windows_file_path(blob->windows_file);
#endif
/* Declare that the annotated function should be exported from the shared
* library (or DLL). */
-#ifdef __WIN32__
+#ifdef _WIN32
# define WIMLIBAPI __declspec(dllexport)
#else
# define WIMLIBAPI __attribute__((visibility("default")))
/* Hint that the annotated function takes a printf()-like format string and
* arguments. This is currently disabled on Windows because MinGW does not
* support this attribute on functions taking wide-character strings. */
-#ifdef __WIN32__
+#ifdef _WIN32
# define _format_attribute(type, format_str, format_start)
#else
# define _format_attribute(type, format_str, format_start) \
extern int
full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset);
-#ifndef __WIN32__
+#ifndef _WIN32
# define O_BINARY 0
#endif
#ifndef _WIMLIB_GLOB_H
#define _WIMLIB_GLOB_H
-#ifndef __WIN32__
+#ifndef _WIN32
# include <glob.h>
#else
#include <stddef.h>
#define GLOB_ABORTED 2 /* Read error. */
#define GLOB_NOMATCH 3 /* No matches found. */
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
#endif /* _WIMLIB_GLOB_H */
* Currently needs to be '/' on UNIX for the WIM mounting code to work properly.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
# define OS_PREFERRED_PATH_SEPARATOR L'\\'
# define is_any_path_separator(c) ((c) == L'/' || (c) == L'\\')
#else
progress_get_streamless_path(const tchar *path)
{
tchar *cookie = NULL;
-#ifdef __WIN32__
+#ifdef _WIN32
cookie = (wchar_t *)path_stream_name(path);
if (cookie)
*--cookie = L'\0'; /* Overwrite the colon */
static inline tchar *
progress_get_win32_path(const tchar *path)
{
-#ifdef __WIN32__
+#ifdef _WIN32
if (!wcsncmp(path, L"\\??\\", 4)) {
((wchar_t *)path)[1] = L'\\';
return (wchar_t *)&path[1];
static inline void
progress_put_win32_path(tchar *cookie)
{
-#ifdef __WIN32__
+#ifdef _WIN32
if (cookie)
*cookie = L'?';
#endif
static inline void
progress_put_streamless_path(tchar *cookie)
{
-#ifdef __WIN32__
+#ifdef _WIN32
if (cookie)
*cookie = L':';
#endif
make_link_reparse_point(const struct link_reparse_point *link,
struct reparse_buffer_disk *rpbuf, u16 *rpbuflen_ret);
-#ifndef __WIN32__
+#ifndef _WIN32
extern int
wim_inode_readlink(const struct wim_inode *inode, char *buf, size_t bufsize,
const struct blob_descriptor *blob,
const tchar *device, struct scan_params *params);
#endif
-#ifdef __WIN32__
+#ifdef _WIN32
/* win32_capture.c */
extern int
win32_build_dentry_tree(struct wim_dentry **root_ret,
extern char *
wimlib_strdup(const char *str);
-#ifdef __WIN32__
+#ifdef _WIN32
extern wchar_t *
wimlib_wcsdup(const wchar_t *str);
#endif
#ifndef _WIMLIB_WIN32_H
#define _WIMLIB_WIN32_H
-#ifdef __WIN32__
+#ifdef _WIN32
#include "wimlib/types.h"
extern ssize_t
win32_pwrite(int fd, const void *buf, size_t count, off_t offset);
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
#endif /* _WIMLIB_WIN32_H */
#include "wimlib/compiler.h"
#include "wimlib/types.h"
-#ifdef __WIN32__
+#ifdef _WIN32
/*
* The Windows Overlay Filesystem filter (WOF, a.k.a. wof.sys) is a filesystem
STATIC_ASSERT(sizeof(struct WimOverlay_dat_entry_2) == 104);
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
#endif /* _WOF_H_ */
/* Functions to act on "tchar" strings, which have a platform-dependent encoding
* and character size. */
-#ifdef __WIN32__
+#ifdef _WIN32
#include <wchar.h>
/*
* For Windows builds, the "tchar" type will be 2 bytes and will be equivalent
_wcserror_s((buf), (bufsize), (errnum))
# define trename win32_rename_replacement
# define tglob win32_wglob
-#else /* __WIN32__ */
+#else /* _WIN32 */
/*
* For non-Windows builds, the "tchar" type will be one byte and will specify a
* string encoded in UTF-8 with the additional possibility of surrogate
# define trename rename
# define taccess access
# define tglob glob
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
#endif /* _WIMLIB_TCHAR_H */
/* Windows-specific code for wimlib-imagex. */
-#ifndef __WIN32__
+#ifndef _WIN32
# error "This file contains Windows code"
#endif
#define WIMLIB_COMPRESSION_TYPE_INVALID (-1)
-#ifdef __WIN32__
+#ifdef _WIN32
# include "imagex-win32.h"
# define print_security_descriptor win32_print_security_descriptor
-#else /* __WIN32__ */
+#else /* _WIN32 */
# include <getopt.h>
# include <langinfo.h>
# define print_security_descriptor default_print_security_descriptor
#ifndef HAVE_GETOPT_LONG_ONLY
# define getopt_long_only getopt_long
#endif
-#endif /* !__WIN32 */
+#endif /* !_WIN32 */
/* Don't confuse the user by presenting the mounting commands on Windows when
* they will never work. However on UNIX-like systems we always present them,
* even if WITH_FUSE is not defined at this point, as to not tie the build of
* wimlib-imagex to a specific build of wimlib. */
-#ifdef __WIN32__
+#ifdef _WIN32
# define WIM_MOUNTING_SUPPORTED 0
#else
# define WIM_MOUNTING_SUPPORTED 1
static tchar *
translate_text_to_tstr(char *text, size_t num_bytes, size_t *num_tchars_ret)
{
-#ifndef __WIN32__
+#ifndef _WIN32
/* On non-Windows, assume an ASCII-compatible encoding, such as UTF-8.
* */
*num_tchars_ret = num_bytes;
return text;
-#else /* !__WIN32__ */
+#else /* !_WIN32 */
/* On Windows, translate the text to UTF-16LE */
wchar_t *text_wstr;
size_t num_wchars;
}
*num_tchars_ret = num_wchars;
return text_wstr;
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
}
static tchar *
* default installation. On UNIX-like systems, warn the
* user when fixing the target of an absolute symbolic
* link, so they know to disable this if they want. */
- #ifndef __WIN32__
+ #ifndef _WIN32
imagex_printf(T("\nWARNING: Adjusted target of "
"absolute symbolic link \"%"TS"\"\n"
" (Use --norpfix to capture "
goto out_wimlib_free;
}
-#ifndef __WIN32__
+#ifndef _WIN32
{
/* Interpret a regular file or block device target as an NTFS
* volume. */
template_image_name_or_num = optarg;
}
}
- #ifdef __WIN32__
+ #ifdef _WIN32
imagex_printf(T("[WARNING] '--update-of' is unreliable on Windows!\n"));
#endif
break;
goto out_free_wim;
}
-#ifndef __WIN32__
+#ifndef _WIN32
/* Detect if source is regular file or block device and set NTFS volume
* capture mode. */
if (!source_list) {
wimlib_iterate_lookup_table(wim, 0, print_resource, NULL);
}
-#ifndef __WIN32__
+#ifndef _WIN32
static void
default_print_security_descriptor(const uint8_t *sd, size_t size)
{
[CMD_VERIFY] = {T("verify"), imagex_verify},
};
-#ifdef __WIN32__
+#ifdef _WIN32
/* Can be a directory or source list file. But source list file is probably
* a rare use case, so just say directory. */
recommend_man_page(int cmd, FILE *fp)
{
const tchar *format_str;
-#ifdef __WIN32__
+#ifdef _WIN32
format_str = T("Some uncommon options are not listed;\n"
"See %"TS".pdf in the doc directory for more details.\n");
#else
recommend_man_page(CMD_NONE, fp);
}
-#ifdef __WIN32__
+#ifdef _WIN32
extern int wmain(int argc, wchar_t **argv);
#define main wmain
#endif
if (new->file_on_disk == NULL)
goto out_free;
break;
-#ifdef __WIN32__
+#ifdef _WIN32
case BLOB_IN_WINDOWS_FILE:
new->windows_file = clone_windows_file(old->windows_file);
break;
(void*)&blob->attached_buffer);
FREE(blob->file_on_disk);
break;
-#ifdef __WIN32__
+#ifdef _WIN32
case BLOB_IN_WINDOWS_FILE:
free_windows_file(blob->windows_file);
break;
/* Compare files by path: just a heuristic that will place files
* in the same directory next to each other. */
return tstrcmp(blob1->file_on_disk, blob2->file_on_disk);
-#ifdef __WIN32__
+#ifdef _WIN32
case BLOB_IN_WINDOWS_FILE:
return cmp_windows_files(blob1->windows_file, blob2->windows_file);
#endif
* WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE or
* WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE to wimlib_global_init(). */
bool default_ignore_case =
-#ifdef __WIN32__
+#ifdef _WIN32
true
#else
false
T("unknown error (errno=%d)"),
errno_save);
}
- #ifdef WIN32
+ #ifdef _WIN32
if (errno_save == EBUSY)
tstrcpy(buf, T("Resource busy"));
#endif
{
FILE *fp;
-#ifdef __WIN32__
+#ifdef _WIN32
fp = win32_open_logfile(path);
#else
fp = fopen(path, "a");
tchar *name;
int raw_fd;
-#ifdef __WIN32__
+#ifdef _WIN32
retry:
name = _wtempnam(NULL, L"wimlib");
if (!name) {
FREE(name);
goto retry;
}
-#else /* __WIN32__ */
+#else /* _WIN32 */
const char *tmpdir = getenv("TMPDIR");
if (!tmpdir)
tmpdir = P_tmpdir;
return WIMLIB_ERR_NOMEM;
sprintf(name, "%s/wimlibXXXXXX", tmpdir);
raw_fd = mkstemp(name);
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
if (raw_fd < 0) {
ERROR_WITH_ERRNO("Failed to create temporary file "
FREE(blob->blob_extraction_targets);
}
-#ifdef __WIN32__
+#ifdef _WIN32
static const utf16lechar replacement_char = cpu_to_le16(0xfffd);
#else
static const utf16lechar replacement_char = cpu_to_le16('?');
return true;
for (i = 0; i < num_chars; i++) {
switch (le16_to_cpu(name[i])) {
- #ifdef __WIN32__
+ #ifdef _WIN32
case '\x01'...'\x1F':
case '\\':
case ':':
if (extract_flags & WIMLIB_EXTRACT_FLAG_NTFS)
return &ntfs_3g_apply_ops;
#endif
-#ifdef __WIN32__
+#ifdef _WIN32
return &win32_apply_ops;
#else
return &unix_apply_ops;
if (errno == EEXIST)
return 0;
-#ifdef __WIN32__
+#ifdef _WIN32
/* _wmkdir() fails with EACCES if called on a drive root directory. */
if (errno == EACCES)
return 0;
#endif
if (extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) {
-#ifdef __WIN32__
+#ifdef _WIN32
if (!wim->filename)
return WIMLIB_ERR_NO_FILENAME;
#else
WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K |
WIMLIB_EXTRACT_FLAG_COMPACT_LZX))
{
- #ifdef __WIN32__
+ #ifdef _WIN32
int count = 0;
count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K) != 0);
count += ((extract_flags & WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K) != 0);
}
static const tchar * const filename_forbidden_chars =
-#ifdef __WIN32__
+#ifdef _WIN32
T("<>:\"/\\|?*");
#else
T("/");
#include "wimlib/file_io.h"
#include "wimlib/util.h"
-#ifdef __WIN32__
+#ifdef _WIN32
# include "wimlib/win32.h"
# define read win32_read
# define write win32_write
#ifdef WITH_FUSE
-#ifdef __WIN32__
+#ifdef _WIN32
# error "FUSE mount not supported on Windows! Please configure --without-fuse"
#endif
static int
mount_unsupported_error(void)
{
-#if defined(__WIN32__)
+#ifdef _WIN32
ERROR("Sorry-- Mounting WIM images is not supported on Windows!");
#else
ERROR("wimlib was compiled with --without-fuse, which disables support "
}
/* UNIX symlink <=> Windows reparse point translation */
-#ifndef __WIN32__
+#ifndef _WIN32
/* Retrieve the inode's reparse point buffer into @rpbuf and @rpbuflen_ret.
* This gets the reparse data from @blob if specified, otherwise from the
return ret;
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
#ifdef WITH_NTFS_3G
[BLOB_IN_NTFS_VOLUME] = read_ntfs_attribute_prefix,
#endif
- #ifdef __WIN32__
+ #ifdef _WIN32
[BLOB_IN_WINDOWS_FILE] = read_windows_file_prefix,
#endif
};
blob_table.capacity]);
break;
case BLOB_IN_FILE_ON_DISK:
- #ifdef __WIN32__
+ #ifdef _WIN32
case BLOB_IN_WINDOWS_FILE:
#endif
blob_set_solid_sort_name_from_inode(blob, blob->file_inode);
static inline bool
is_valid_filename_char(utf16lechar c)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return is_valid_windows_filename_char(c);
#else
return c != cpu_to_le16('\0') && c != cpu_to_le16('/');
static bool
am_root(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return false;
#else
return (getuid() == 0);
static u32
generate_uid(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return 0;
#else
if (am_root())
static u32
generate_gid(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return 0;
#else
if (am_root())
#endif
}
-#ifdef __WIN32__
+#ifdef _WIN32
# ifndef S_IFLNK
# define S_IFLNK 0120000
# endif
struct wim_xattr_entry *entry = (void *)entries;
size_t entries_size;
struct wimlib_unix_data unix_data;
-#ifdef __WIN32__
+#ifdef _WIN32
const char *prefix = "";
#else
const char *prefix = "user.";
int value_len = rand32() % 64;
u8 *p;
- #ifdef __WIN32__
+ #ifdef _WIN32
if (value_len == 0)
value_len++;
#endif
*p++ = 'A' + i;
for (int j = 1; j < name_len; j++) {
do {
- #ifdef __WIN32__
+ #ifdef _WIN32
*p = 'A' + rand8() % 26;
#else
*p = rand8();
*high_part_ret = sec >> 32;
}
-#ifdef __WIN32__
+#ifdef _WIN32
static _unused_attribute void
check_sizeof_time_t(void)
{
gettimeofday(&tv, NULL);
return timeval_to_wim_timestamp(&tv);
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
/* Translate a WIM timestamp into a human-readable string. */
void
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifndef __WIN32__
+#ifndef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
root_disk_path, params);
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
}
#endif
-#ifdef __WIN32__
+#ifdef _WIN32
/* Check for flags not supported on Windows. */
if (add_flags & WIMLIB_ADD_FLAG_UNIX_DATA) {
ERROR("Capturing UNIX-specific data is not supported on Windows");
return memdup(str, strlen(str) + 1);
}
-#ifdef __WIN32__
+#ifdef _WIN32
wchar_t *
wimlib_wcsdup(const wchar_t *str)
{
* Random number generation
**************************/
-#ifndef __WIN32__
+#ifndef _WIN32
/*
* Generate @n cryptographically secure random bytes (thread-safe)
*
} while (n != 0);
close(fd);
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
/*
* Generate @n cryptographically secure random alphanumeric characters
* System information
************************/
-#ifndef __WIN32__
+#ifndef _WIN32
unsigned
get_available_cpus(void)
{
}
return n;
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
-#ifndef __WIN32__
+#ifndef _WIN32
u64
get_available_memory(void)
{
WARNING("Failed to determine available memory; assuming 1 GiB");
return (u64)1 << 30;
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
init_cpu_features();
xml_global_init();
-#ifdef __WIN32__
+#ifdef _WIN32
ret = win32_global_init(init_flags);
if (ret)
goto out_unlock;
goto out_unlock;
xml_global_cleanup();
-#ifdef __WIN32__
+#ifdef _WIN32
win32_global_cleanup();
#endif
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
return true;
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
.context_size = sizeof(struct win32_apply_ctx),
};
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
return ret;
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
return status;
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
return ((u64)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
* along with this file; if not, see http://www.gnu.org/licenses/.
*/
-#ifdef __WIN32__
+#ifdef _WIN32
#ifdef HAVE_CONFIG_H
# include "config.h"
return ret;
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
if (ret) {
ERROR_WITH_ERRNO("Failed to rename `%"TS"' to `%"TS"'",
tmpfile, wim->filename);
- #ifdef __WIN32__
+ #ifdef _WIN32
if (ret < 0)
#endif
{
#endif
#include <unistd.h>
-#ifdef __WIN32__
+#ifdef _WIN32
# include <windows.h>
# include <winternl.h>
# include <ntstatus.h>
static void
change_to_temporary_directory(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
ASSERT(SetCurrentDirectory(L"E:\\"),
"failed to change directory to E:\\");
#else
}
#endif /* WITH_NTFS_3G */
-#ifdef __WIN32__
+#ifdef _WIN32
extern WINAPI NTSTATUS NtQueryDirectoryFile (HANDLE FileHandle,
HANDLE Event,
ASSERT(GetFileAttributes(name) == 0xFFFFFFFF, "Deletion didn't work!");
}
-#else /* __WIN32__ */
+#else /* _WIN32 */
static void
delete_directory_tree_recursive(int dirfd, const char *name)
delete_directory_tree_recursive(AT_FDCWD, name);
}
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
static uint32_t
rand32(void)
return info.image_count;
}
-#ifdef __WIN32__
+#ifdef _WIN32
static bool
is_wimboot_capable(WIMStruct *wim)
{
(info.compression_type == WIMLIB_COMPRESSION_TYPE_LZX &&
info.chunk_size == 32768));
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
static void
overwrite_wim(WIMStruct *wim)
} else
#endif
{
-#ifdef __WIN32__
+#ifdef _WIN32
printf("applying in Windows mode\n");
cmp_flags |= WIMLIB_CMP_FLAG_WINDOWS_MODE;
-#else /* __WIN32__ */
+#else /* _WIN32 */
printf("applying in UNIX mode\n");
extract_flags |= WIMLIB_EXTRACT_FLAG_UNIX_DATA;
add_flags |= WIMLIB_ADD_FLAG_UNIX_DATA;
cmp_flags |= WIMLIB_CMP_FLAG_UNIX_MODE;
-#endif /* !__WIN32__ */
+#endif /* !_WIN32 */
}
add_flags |= WIMLIB_ADD_FLAG_NORPFIX;
CHECK_RET(wimlib_extract_image(wim, image, TMP_TARGET_NAME,
wimlib_free(wim);
}
-#ifdef __WIN32__
+#ifdef _WIN32
/* Enumerate and unregister all backing WIMs from the specified volume */
static void
wimlib_free(wim);
wimlib_free(wim2);
}
-#endif /* __WIN32__ */
+#endif /* _WIN32 */
static int
is_solid_resource(const struct wimlib_resource_entry *resource, void *_ctx)
op__apply_and_capture_test,
op__split_test,
op__set_compression_level,
-#ifdef __WIN32__
+#ifdef _WIN32
op__wimboot_test,
#endif
};
-#ifdef __WIN32__
+#ifdef _WIN32
extern int wmain(int argc, wchar_t **argv);
#define main wmain
#endif