Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ static int terminate_process(DWORD pid, HANDLE process_handle, int sig);
static int my_killpg(int pid, int sig);
static int my_kill(int pid, int sig);
static void out_of_memory(const char *context, STRLEN len);
#ifdef _DEBUG
static char* wstr_to_str(const wchar_t* wstr);
#endif
static long filetime_to_clock(PFILETIME ft);
static BOOL filetime_from_time(PFILETIME ft, time_t t);
static char* create_command_line(char *cname, STRLEN clen,
Expand Down Expand Up @@ -1199,6 +1201,9 @@ int
chown(const char *path, uid_t owner, gid_t group)
{
/* XXX noop */
PERL_UNUSED_ARG(path);
PERL_UNUSED_ARG(owner);
PERL_UNUSED_ARG(group);
return 0;
}

Expand Down Expand Up @@ -1455,7 +1460,7 @@ win32_kill(int pid, int sig)
/* kill -9 style un-graceful exit */
/* Do a wait to make sure child starts and isn't in DLL
* Loader Lock */
HWND hwnd = get_hwnd_delay(aTHX, child, 5);
(void)get_hwnd_delay(aTHX, child, 5);
if (TerminateThread(hProcess, sig)) {
/* Allow the scheduler to finish cleaning up the other
* thread.
Expand Down Expand Up @@ -1856,7 +1861,6 @@ DllExport int
win32_stat(const char *path, Stat_t *sbuf)
{
dTHX;
BOOL expect_dir = FALSE;
int result;
HANDLE handle;
DWORD reparse_type = 0;
Expand Down Expand Up @@ -1937,8 +1941,6 @@ translate_to_errno(void)
static BOOL
is_symlink(HANDLE h) {
MY_REPARSE_DATA_BUFFER linkdata;
const MY_SYMLINK_REPARSE_BUFFER * const sd =
&linkdata.Data.SymbolicLinkReparseBuffer;
DWORD linkdata_returned;

if (!DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, NULL, 0, &linkdata, sizeof(linkdata), &linkdata_returned, NULL)) {
Expand Down Expand Up @@ -2243,6 +2245,7 @@ win32_croak_not_implemented(const char * fname)
Perl_croak_nocontext("%s not implemented!\n", fname);
}

#ifdef _DEBUG
/* Converts a wide character (UTF-16) string to the Windows ANSI code page,
* potentially using the system's default replacement character for any
* unrepresentable characters. The caller must free() the returned string. */
Expand All @@ -2260,6 +2263,7 @@ wstr_to_str(const wchar_t* wstr)
str, len, NULL, &used_default);
return str;
}
#endif

/* The win32_ansipath() function takes a Unicode filename and converts it
* into the current Windows codepage. If some characters cannot be mapped,
Expand Down Expand Up @@ -2604,6 +2608,7 @@ DllExport int
win32_gettimeofday(struct timeval *tp, void *not_used)
{
FT_t ft;
PERL_UNUSED_ARG(not_used);

/* this returns time in 100-nanosecond units (i.e. tens of usecs) */
GetSystemTimeAsFileTime(&ft.ft_val);
Expand Down Expand Up @@ -3543,25 +3548,18 @@ do_popen(const char *mode, const char *command, IV narg, SV **args) {
int p[2];
int handles[3];
int parent, child;
int stdfd;
int ourmode;
int childpid;
DWORD nhandle;
int lock_held = 0;
const char **args_pvs = NULL;

/* establish which ends read and write */
if (strchr(mode,'w')) {
stdfd = 0; /* stdin */
parent = 1;
child = 0;
nhandle = STD_INPUT_HANDLE;
}
else if (strchr(mode,'r')) {
stdfd = 1; /* stdout */
parent = 0;
child = 1;
nhandle = STD_OUTPUT_HANDLE;
}
else
return NULL;
Expand Down Expand Up @@ -3805,7 +3803,6 @@ win32_symlink(const char *oldfile, const char *newfile)
/* dest_path = oldfile; already done */
}
else if (oldfile[0] != '\\') {
size_t newfile_len = strlen(newfile);
const char *last_slash = strrchr(newfile, '/');
const char *last_bslash = strrchr(newfile, '\\');
const char *end_dir = last_slash && last_bslash
Expand Down Expand Up @@ -3910,10 +3907,11 @@ win32_chsize(int fd, Off_t size)
/* must grow the file, padding with nulls */
char b[4096];
int oldmode = win32_setmode(fd, O_BINARY);
size_t count;
Off_t count;
memset(b, '\0', sizeof(b));
do {
count = extend >= sizeof(b) ? sizeof(b) : (size_t)extend;
/* Casts to 'Off_t' avoid '[-Wsign-compare]' warning */
count = extend >= (Off_t)sizeof(b) ? (Off_t)sizeof(b) : extend;
count = win32_write(fd, b, count);
if ((int)count < 0) {
retval = -1;
Expand Down Expand Up @@ -4143,6 +4141,7 @@ DllExport int
win32_mkdir(const char *dir, int mode)
{
dTHX;
PERL_UNUSED_ARG(mode);
return mkdir(PerlDir_mapA(dir)); /* just ignore mode */
}

Expand Down Expand Up @@ -4182,7 +4181,7 @@ static char *
create_command_line(char *cname, STRLEN clen, const char * const *args)
{
PERL_DEB(dTHX;)
int index, argc;
int index;
char *cmd, *ptr;
const char *arg;
STRLEN len = 0;
Expand Down Expand Up @@ -4252,7 +4251,6 @@ create_command_line(char *cname, STRLEN clen, const char * const *args)
}
DEBUG_p(PerlIO_printf(Perl_debug_log, "\n"));

argc = index;
Newx(cmd, len, char);
ptr = cmd;

Expand Down Expand Up @@ -4449,6 +4447,7 @@ win32_get_childenv(void)
DllExport void
win32_free_childenv(void* d)
{
PERL_UNUSED_ARG(d);
}

DllExport void
Expand Down Expand Up @@ -4744,7 +4743,9 @@ win32_fgets(char *s, int n, FILE *pf)
DllExport char*
win32_gets(char *s)
{
GCC_DIAG_IGNORE_STMT(-Wattribute-warning); /* gets() only for compat */
return gets(s);
GCC_DIAG_RESTORE_STMT;
}

DllExport int
Expand Down Expand Up @@ -5006,6 +5007,7 @@ XS(w32_SetChildShowWindow)
XS(w32_GetCwd)
{
dXSARGS;
PERL_UNUSED_VAR(items);
/* Make the host for current directory */
char* ptr = PerlEnv_get_childdir();
/*
Expand Down Expand Up @@ -5258,7 +5260,7 @@ win32_hook_imported_function_in_module(
= (PIMAGE_THUNK_DATA)(image_base + idt->FirstThunk);

ULONG_PTR address_of_data;
for (; address_of_data = ilt->u1.AddressOfData; ++ilt, ++iat) {
for (; (address_of_data = ilt->u1.AddressOfData); ++ilt, ++iat) {
/* Ordinal imports are quite rare, so skipping them will most likely
* not cause any problems. */
BOOL is_ordinal
Expand Down Expand Up @@ -5346,12 +5348,12 @@ my_CloseHandle(HANDLE h)
}
}

if (maybe_socket)
if (maybe_socket) {
if (closesocket((SOCKET)h) == 0)
return TRUE;
else if (WSAGetLastError() != WSAENOTSOCK)
return FALSE;

}
return CloseHandle_orig(h);
}

Expand Down Expand Up @@ -5414,6 +5416,8 @@ win32_unhook_closehandle_in_crt()
void
Perl_win32_init(int *argcp, char ***argvp)
{
PERL_UNUSED_ARG(argcp);
PERL_UNUSED_ARG(argvp);
#ifdef SET_INVALID_PARAMETER_HANDLER
_invalid_parameter_handler oldHandler, newHandler;
newHandler = my_invalid_parameter_handler;
Expand Down Expand Up @@ -5563,7 +5567,8 @@ win32_process_message(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
* complexity of getting the correct context passed into
* win32_create_message_window() */
dTHX;

PERL_UNUSED_ARG(hwnd);
PERL_UNUSED_ARG(lParam);
switch(msg) {

#ifdef USE_ITHREADS
Expand Down Expand Up @@ -5649,6 +5654,7 @@ win32_csighandler(int sig)
dTHXa(PERL_GET_SIG_CONTEXT);
Perl_warn(aTHX_ "Got signal %d",sig);
#endif
PERL_UNUSED_ARG(sig);
/* Does nothing */
}

Expand Down