#endif
#include <windows.h>
+#include <lmcons.h>
+#include <lmerr.h>
+/* ugliness to work around a buggy struct definition in lmwksta.h */
+#undef LPTSTR
+#define LPTSTR LPWSTR
+#include <lmwksta.h>
+#undef LPTSTR
+#define LPTSTR LPSTR
+
/* #include "config.h" */
#define PERLIO_NOT_STDIO 0
* Scan string looking for redirection (< or >) or pipe
* characters (|) that are not in a quoted string
*/
- while(*ptr) {
+ while (*ptr) {
switch(*ptr) {
case '\'':
case '\"':
- if(inquote) {
- if(quote == *ptr) {
+ if (inquote) {
+ if (quote == *ptr) {
inquote = 0;
quote = '\0';
}
case '>':
case '<':
case '|':
- if(!inquote)
+ if (!inquote)
return TRUE;
default:
break;
flag = SvIVx(*mark);
}
- while(++mark <= sp) {
+ while (++mark <= sp) {
if (*mark && (str = SvPV(*mark, na)))
argv[index++] = str;
else
/* Save an extra exec if possible. See if there are shell
* metacharacters in it */
- if(!has_redirection(cmd)) {
+ if (!has_redirection(cmd)) {
New(1301,argv, strlen(cmd) / 2 + 2, char*);
New(1302,cmd2, strlen(cmd) + 1, char);
strcpy(cmd2, cmd);
s++;
if (*s)
*(a++) = s;
- while(*s && !isspace(*s))
+ while (*s && !isspace(*s))
s++;
- if(*s)
+ if (*s)
*s++ = '\0';
}
*a = Nullch;
return FALSE;
}
-
-#define PATHLEN 1024
-
/* The idea here is to read all the directory names into a string table
* (separated by nulls) and when one of the other dir functions is called
* return the pointer to the current file name.
DIR *
opendir(char *filename)
{
- DIR *p;
- long len;
- long idx;
- char scannamespc[PATHLEN];
- char *scanname = scannamespc;
- struct stat sbuf;
- WIN32_FIND_DATA FindData;
- HANDLE fh;
-/* char root[_MAX_PATH];*/
-/* char volname[_MAX_PATH];*/
-/* DWORD serial, maxname, flags;*/
-/* BOOL downcase;*/
-/* char *dummy;*/
+ DIR *p;
+ long len;
+ long idx;
+ char scanname[MAX_PATH+3];
+ struct stat sbuf;
+ WIN32_FIND_DATA FindData;
+ HANDLE fh;
+
+ len = strlen(filename);
+ if (len > MAX_PATH)
+ return NULL;
/* check to see if filename is a directory */
if (win32_stat(filename, &sbuf) < 0 || (sbuf.st_mode & S_IFDIR) == 0) {
return NULL;
}
- /* get the file system characteristics */
-/* if(GetFullPathName(filename, MAX_PATH, root, &dummy)) {
- * if(dummy = strchr(root, '\\'))
- * *++dummy = '\0';
- * if(GetVolumeInformation(root, volname, MAX_PATH, &serial,
- * &maxname, &flags, 0, 0)) {
- * downcase = !(flags & FS_CASE_IS_PRESERVED);
- * }
- * }
- * else {
- * downcase = TRUE;
- * }
- */
/* Get us a DIR structure */
Newz(1303, p, 1, DIR);
- if(p == NULL)
+ if (p == NULL)
return NULL;
/* Create the search pattern */
strcpy(scanname, filename);
-
- if(index("/\\", *(scanname + strlen(scanname) - 1)) == NULL)
- strcat(scanname, "/*");
- else
- strcat(scanname, "*");
+ if (scanname[len-1] != '/' && scanname[len-1] != '\\')
+ scanname[len++] = '/';
+ scanname[len++] = '*';
+ scanname[len] = '\0';
/* do the FindFirstFile call */
fh = FindFirstFile(scanname, &FindData);
- if(fh == INVALID_HANDLE_VALUE) {
+ if (fh == INVALID_HANDLE_VALUE) {
return NULL;
}
*/
idx = strlen(FindData.cFileName)+1;
New(1304, p->start, idx, char);
- if(p->start == NULL) {
+ if (p->start == NULL)
croak("opendir: malloc failed!\n");
- }
strcpy(p->start, FindData.cFileName);
-/* if(downcase)
- * strlwr(p->start);
- */
p->nfiles++;
/* loop finding all the files that match the wildcard
* new name and it's null terminator
*/
Renew(p->start, idx+len+1, char);
- if(p->start == NULL) {
+ if (p->start == NULL)
croak("opendir: malloc failed!\n");
- }
strcpy(&p->start[idx], FindData.cFileName);
-/* if (downcase)
- * strlwr(&p->start[idx]);
- */
- p->nfiles++;
- idx += len+1;
- }
- FindClose(fh);
- p->size = idx;
- p->curr = p->start;
- return p;
+ p->nfiles++;
+ idx += len+1;
+ }
+ FindClose(fh);
+ p->size = idx;
+ p->curr = p->start;
+ return p;
}
/* copy relevant flags from second parameter */
fileflags = FDEV;
- if(flags & O_APPEND)
+ if (flags & O_APPEND)
fileflags |= FAPPEND;
- if(flags & O_TEXT)
+ if (flags & O_TEXT)
fileflags |= FTEXT;
/* attempt to allocate a C Runtime file handle */
- if((fh = _alloc_osfhnd()) == -1) {
+ if ((fh = _alloc_osfhnd()) == -1) {
errno = EMFILE; /* too many open files */
_doserrno = 0L; /* not an OS error */
return -1; /* return error to caller */
#endif
DWORD source = 0;
- if(e < 0 || e > sys_nerr) {
+ if (e < 0 || e > sys_nerr) {
dTHR;
- if(e < 0)
+ if (e < 0)
e = GetLastError();
- if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, &source, e, 0,
strerror_buffer, sizeof(strerror_buffer), NULL) == 0)
strcpy(strerror_buffer, "Unknown Error");
XS(w32_DomainName)
{
dXSARGS;
+#if 0
+ /* doesn't do the right thing if current user is a local account */
char name[256];
DWORD size = sizeof(name);
if (GetUserName(name,&size)) {
XSRETURN_PV(dname); /* all that for this */
}
}
+#else
+ char dname[256];
+ DWORD dnamelen = sizeof(dname);
+ WKSTA_INFO_100 wi;
+ if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&wi)) {
+ WideCharToMultiByte(CP_ACP, NULL, wi.wki100_langroup, -1,
+ (LPSTR)dname, dnamelen, NULL, NULL);
+ XSRETURN_PV(dname);
+ }
+#endif
XSRETURN_UNDEF;
}
STARTUPINFO stStartInfo;
BOOL bSuccess = FALSE;
- if(items != 3)
+ if (items != 3)
croak("usage: Win32::Spawn($cmdName, $args, $PID)");
cmd = SvPV(ST(0),na);
stStartInfo.dwFlags = STARTF_USESHOWWINDOW; /* Enable wShowWindow control */
stStartInfo.wShowWindow = SW_SHOWMINNOACTIVE; /* Start min (normal) */
- if(CreateProcess(
+ if (CreateProcess(
cmd, /* Image path */
args, /* Arguments for command line */
NULL, /* Default process security */
SV *shortpath;
DWORD len;
- if(items != 1)
+ if (items != 1)
croak("usage: Win32::GetShortPathName($longPathName)");
shortpath = sv_mortalcopy(ST(0));