116
116
code = GetLastError();
118
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
118
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
119
119
nil, code, 0, (Rune*)&r, 0, nil);
121
121
return bstr(&b); // leak but we're dying anyway
272
272
genrun(Buf *b, char *dir, int mode, Vec *argv, int wait)
274
// Another copy of this logic is in ../../lib9/run_windows.c.
275
// If there's a bug here, fix the logic there too.
274
276
int i, j, nslash;
287
289
for(i=0; i<argv->len; i++) {
291
if(i == 0 && streq(q, "hg"))
292
bwritestr(&cmd, "cmd.exe /c ");
289
294
bwritestr(&cmd, " ");
291
295
if(contains(q, " ") || contains(q, "\t") || contains(q, "\"") || contains(q, "\\\\") || hassuffix(q, "\\")) {
292
296
bwritestr(&cmd, "\"");
532
xprintf("read %s\n", file);
537
errprintf("read %s\n", file);
533
538
torune(&r, file);
534
539
h = CreateFileW(r, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
535
540
if(h == INVALID_HANDLE_VALUE)
551
xprintf("write %s\n", file);
556
errprintf("write %s\n", file);
552
557
torune(&r, file);
553
558
h = CreateFileW(r, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, CREATE_ALWAYS, 0, 0);
554
559
if(h == INVALID_HANDLE_VALUE)
707
712
vsnprintf(buf1, sizeof buf1, msg, arg);
710
xprintf("go tool dist: %s\n", buf1);
715
errprintf("go tool dist: %s\n", buf1);
857
errprintf(char *fmt, ...)
864
n = vsnprintf(NULL, 0, fmt, arg);
866
vsnprintf(p, n+1, fmt, arg);
869
WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
852
874
main(int argc, char **argv)
932
// xsamefile returns whether f1 and f2 are the same file (or dir)
934
xsamefile(char *f1, char *f2)
938
BY_HANDLE_FILE_INFORMATION fi1, fi2;
946
// refer to ../../pkg/os/stat_windows.go:/sameFile
947
fd1 = CreateFileW(ru, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
949
if(fd1 == INVALID_HANDLE_VALUE)
952
fd2 = CreateFileW(ru, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
954
if(fd2 == INVALID_HANDLE_VALUE) {
958
r = GetFileInformationByHandle(fd1, &fi1) != 0 && GetFileInformationByHandle(fd2, &fi2) != 0;
962
fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
963
fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
964
fi1.nFileIndexLow == fi2.nFileIndexLow)
969
// xtryexecfunc tries to execute function f, if any illegal instruction
970
// signal received in the course of executing that function, it will
971
// return 0, otherwise it will return 1.
973
xtryexecfunc(void (*f)(void))
975
return 0; // suffice for now
979
cpuid(int dst[4], int ax)
981
// NOTE: This asm statement is for mingw.
982
// If we ever support MSVC, use __cpuid(dst, ax)
983
// to use the built-in.
984
#if defined(__i386__) || defined(__x86_64__)
986
: "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
989
dst[0] = dst[1] = dst[2] = dst[3] = 0;
999
return (info[3] & (1<<26)) != 0; // SSE2
910
1003
#endif // __WINDOWS__