~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/dist/windows.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
        binit(&b);
116
116
        code = GetLastError();
117
117
        r = nil;
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);
120
120
        toutf(&b, r);
121
121
        return bstr(&b);  // leak but we're dying anyway
271
271
static void
272
272
genrun(Buf *b, char *dir, int mode, Vec *argv, int wait)
273
273
{
 
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;
275
277
        Buf cmd;
276
278
        char *q;
285
287
        binit(&cmd);
286
288
 
287
289
        for(i=0; i<argv->len; i++) {
 
290
                q = argv->p[i];
 
291
                if(i == 0 && streq(q, "hg"))
 
292
                        bwritestr(&cmd, "cmd.exe /c ");
288
293
                if(i > 0)
289
294
                        bwritestr(&cmd, " ");
290
 
                q = argv->p[i];
291
295
                if(contains(q, " ") || contains(q, "\t") || contains(q, "\"") || contains(q, "\\\\") || hassuffix(q, "\\")) {
292
296
                        bwritestr(&cmd, "\"");
293
297
                        nslash = 0;
314
318
                }
315
319
        }
316
320
        if(vflag > 1)
317
 
                xprintf("%s\n", bstr(&cmd));
 
321
                errprintf("%s\n", bstr(&cmd));
318
322
 
319
323
        torune(&rcmd, bstr(&cmd));
320
324
        rexe = nil;
528
532
        HANDLE h;
529
533
        Rune *r;
530
534
 
 
535
        breset(b);
531
536
        if(vflag > 2)
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)
548
553
        USED(exec);
549
554
 
550
555
        if(vflag > 2)
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);
708
713
        va_end(arg);
709
714
 
710
 
        xprintf("go tool dist: %s\n", buf1);
 
715
        errprintf("go tool dist: %s\n", buf1);
711
716
        
712
717
        bgwait();
713
718
        ExitProcess(1);
848
853
        xfree(p);
849
854
}
850
855
 
 
856
void
 
857
errprintf(char *fmt, ...)
 
858
{
 
859
        va_list arg;
 
860
        char *p;
 
861
        DWORD n, w;
 
862
 
 
863
        va_start(arg, fmt);
 
864
        n = vsnprintf(NULL, 0, fmt, arg);
 
865
        p = xmalloc(n+1);
 
866
        vsnprintf(p, n+1, fmt, arg);
 
867
        va_end(arg);
 
868
        w = 0;
 
869
        WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
 
870
        xfree(p);
 
871
}
 
872
 
851
873
int
852
874
main(int argc, char **argv)
853
875
{
907
929
        return nil;
908
930
}
909
931
 
 
932
// xsamefile returns whether f1 and f2 are the same file (or dir)
 
933
int
 
934
xsamefile(char *f1, char *f2)
 
935
{
 
936
        Rune *ru;
 
937
        HANDLE fd1, fd2;
 
938
        BY_HANDLE_FILE_INFORMATION fi1, fi2;
 
939
        int r;
 
940
 
 
941
        // trivial case
 
942
        if(streq(f1, f2))
 
943
                return 1;
 
944
        
 
945
        torune(&ru, f1);
 
946
        // refer to ../../pkg/os/stat_windows.go:/sameFile
 
947
        fd1 = CreateFileW(ru, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
 
948
        xfree(ru);
 
949
        if(fd1 == INVALID_HANDLE_VALUE)
 
950
                return 0;
 
951
        torune(&ru, f2);
 
952
        fd2 = CreateFileW(ru, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
 
953
        xfree(ru);
 
954
        if(fd2 == INVALID_HANDLE_VALUE) {
 
955
                CloseHandle(fd1);
 
956
                return 0;
 
957
        }
 
958
        r = GetFileInformationByHandle(fd1, &fi1) != 0 && GetFileInformationByHandle(fd2, &fi2) != 0;
 
959
        CloseHandle(fd2);
 
960
        CloseHandle(fd1);
 
961
        if(r != 0 &&
 
962
           fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
 
963
           fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
 
964
           fi1.nFileIndexLow == fi2.nFileIndexLow)
 
965
                return 1;
 
966
        return 0;
 
967
}
 
968
 
 
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.
 
972
int
 
973
xtryexecfunc(void (*f)(void))
 
974
{
 
975
        return 0; // suffice for now
 
976
}
 
977
 
 
978
static void
 
979
cpuid(int dst[4], int ax)
 
980
{
 
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__)
 
985
        asm volatile("cpuid"
 
986
                : "=a" (dst[0]), "=b" (dst[1]), "=c" (dst[2]), "=d" (dst[3])
 
987
                : "0" (ax));
 
988
#else
 
989
        dst[0] = dst[1] = dst[2] = dst[3] = 0;
 
990
#endif
 
991
}
 
992
 
 
993
bool
 
994
cansse2(void)
 
995
{
 
996
        int info[4];
 
997
        
 
998
        cpuid(info, 1);
 
999
        return (info[3] & (1<<26)) != 0;        // SSE2
 
1000
}
 
1001
 
 
1002
 
910
1003
#endif // __WINDOWS__