* for).
*/
const char* defaultshell = (IsWinNT()
- ? "cmd.exe /x/c" : "command.com /c");
+ ? "cmd.exe /x/d/c" : "command.com /c");
const char *usershell = PerlEnv_getenv("PERL5SHELL");
w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
&w32_perlshell_tokens,
return ours;
}
+/* This function will not return until the timeout has elapsed, or until
+ * one of the handles is ready. */
DllExport DWORD
win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD resultp)
{
}
if (result == WAIT_OBJECT_0 + count) {
/* Message has arrived - check it */
- if (win32_async_check(aTHX)) {
- /* was one of ours */
- break;
- }
+ (void)win32_async_check(aTHX);
}
else {
/* Not timeout or message - one of handles is ready */
return;
}
-DllExport FILE*
-win32_tmpfile(void)
+DllExport int
+win32_tmpfd(void)
{
dTHX;
char prefix[MAX_PATH+1];
#endif
DEBUG_p(PerlIO_printf(Perl_debug_log,
"Created tmpfile=%s\n",filename));
- return fdopen(fd, "w+b");
+ return fd;
}
}
}
}
+ return -1;
+}
+
+DllExport FILE*
+win32_tmpfile(void)
+{
+ int fd = win32_tmpfd();
+ if (fd >= 0)
+ return win32_fdopen(fd, "w+b");
return NULL;
}
if ((oldfd = win32_dup(stdfd)) == -1)
goto cleanup;
+ /* save the old std handle (this needs to happen before the
+ * dup2(), since that might call SetStdHandle() too) */
+ OP_REFCNT_LOCK;
+ lock_held = 1;
+ old_h = GetStdHandle(nhandle);
+
/* make stdfd go to child end of pipe (implicitly closes stdfd) */
/* stdfd will be inherited by the child */
if (win32_dup2(p[child], stdfd) == -1)
/* close the child end in parent */
win32_close(p[child]);
- /* save the old std handle, and set the std handle */
- OP_REFCNT_LOCK;
- lock_held = 1;
- old_h = GetStdHandle(nhandle);
+ /* set the new std handle (in case dup2() above didn't) */
SetStdHandle(nhandle, (HANDLE)_get_osfhandle(stdfd));
/* start the child */
if ((childpid = do_spawn_nowait((char*)command)) == -1)
goto cleanup;
- /* restore the old std handle */
+ /* revert stdfd to whatever it was before */
+ if (win32_dup2(oldfd, stdfd) == -1)
+ goto cleanup;
+
+ /* restore the old std handle (this needs to happen after the
+ * dup2(), since that might call SetStdHandle() too */
if (lock_held) {
SetStdHandle(nhandle, old_h);
OP_REFCNT_UNLOCK;
lock_held = 0;
}
- /* revert stdfd to whatever it was before */
- if (win32_dup2(oldfd, stdfd) == -1)
- goto cleanup;
-
/* close saved handle */
win32_close(oldfd);
return setmode(fd, mode);
}
+DllExport int
+win32_chsize(int fd, Off_t size)
+{
+#if defined(WIN64) || defined(USE_LARGE_FILES)
+ int retval = 0;
+ Off_t cur, end, extend;
+
+ cur = win32_tell(fd);
+ if (cur < 0)
+ return -1;
+ end = win32_lseek(fd, 0, SEEK_END);
+ if (end < 0)
+ return -1;
+ extend = size - end;
+ if (extend == 0) {
+ /* do nothing */
+ }
+ else if (extend > 0) {
+ /* must grow the file, padding with nulls */
+ char b[4096];
+ int oldmode = win32_setmode(fd, O_BINARY);
+ size_t count;
+ memset(b, '\0', sizeof(b));
+ do {
+ count = extend >= sizeof(b) ? sizeof(b) : (size_t)extend;
+ count = win32_write(fd, b, count);
+ if (count < 0) {
+ retval = -1;
+ break;
+ }
+ } while ((extend -= count) > 0);
+ win32_setmode(fd, oldmode);
+ }
+ else {
+ /* shrink the file */
+ win32_lseek(fd, size, SEEK_SET);
+ if (!SetEndOfFile((HANDLE)_get_osfhandle(fd))) {
+ errno = EACCES;
+ retval = -1;
+ }
+ }
+finish:
+ win32_lseek(fd, cur, SEEK_SET);
+ return retval;
+#else
+ return chsize(fd, size);
+#endif
+}
+
DllExport Off_t
win32_lseek(int fd, Off_t offset, int origin)
{
if (!extra_quotes
&& cmd_shell
- && (stricmp(arg, "/x/c") == 0 || stricmp(arg, "/c") == 0))
+ && curlen >= 2
+ && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
+ && stricmp(arg+curlen-2, "/c") == 0)
{
/* is there a next argument? */
if (args[index+1]) {
/* if this is a pseudo-forked child, we just want to spawn
* the new program, and return */
if (w32_pseudo_id) {
- int status = win32_spawnvp(P_WAIT, cmdname, (char *const *)argv);
+ int status = win32_spawnvp(P_WAIT, cmdname, (const char *const *)argv);
if (status != -1) {
my_exit(status);
return 0;
/* NERR_Success *is* 0*/
if (0 == pfnNetWkstaGetInfo(NULL, 100, &pwi)) {
if (pwi->wki100_langroup && *(pwi->wki100_langroup)) {
- WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_langroup,
+ WideCharToMultiByte(CP_ACP, 0, pwi->wki100_langroup,
-1, (LPSTR)dname, dnamelen, NULL, NULL);
}
else {
- WideCharToMultiByte(CP_ACP, NULL, pwi->wki100_computername,
+ WideCharToMultiByte(CP_ACP, 0, pwi->wki100_computername,
-1, (LPSTR)dname, dnamelen, NULL, NULL);
}
pfnNetApiBufferFree(pwi);
} while (len >= SvLEN(shortpath) && sv_grow(shortpath,len+1));
if (len) {
SvCUR_set(shortpath,len);
+ *SvEND(shortpath) = '\0';
ST(0) = shortpath;
XSRETURN(1);
}
if (len) {
if (GIMME_V == G_ARRAY) {
EXTEND(SP,1);
- XST_mPV(1,filepart);
- len = filepart - SvPVX(fullpath);
+ if (filepart) {
+ XST_mPV(1,filepart);
+ len = filepart - SvPVX(fullpath);
+ }
+ else {
+ XST_mPVN(1,"",0);
+ }
items = 2;
}
SvCUR_set(fullpath,len);
+ *SvEND(fullpath) = '\0';
ST(0) = fullpath;
XSRETURN(items);
}
}
void
+Perl_win32_term(void)
+{
+ OP_REFCNT_TERM;
+ MALLOC_TERM;
+}
+
+void
win32_get_child_IO(child_IO_table* ptbl)
{
ptbl->childStdIn = GetStdHandle(STD_INPUT_HANDLE);