LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // These #ifdefs are being used as a substitute for | 5 // These #ifdefs are being used as a substitute for |
6 // build configuration, so that on any system, this | 6 // build configuration, so that on any system, this |
7 // tool can be built with the local equivalent of | 7 // tool can be built with the local equivalent of |
8 // cc *.c | 8 // cc *.c |
9 // | 9 // |
10 #ifndef WIN32 | 10 #ifndef WIN32 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 int fd; | 344 int fd; |
345 ········ | 345 ········ |
346 breset(b); | 346 breset(b); |
347 fd = open(file, 0); | 347 fd = open(file, 0); |
348 if(fd < 0) | 348 if(fd < 0) |
349 fatal("open %s: %s", file, strerror(errno)); | 349 fatal("open %s: %s", file, strerror(errno)); |
350 breadfrom(b, fd); | 350 breadfrom(b, fd); |
351 close(fd); | 351 close(fd); |
352 } | 352 } |
353 | 353 |
354 // writefile writes b to the named file, creating it if needed. | 354 // writefile writes b to the named file, creating it if needed. if |
355 void | 355 // exec is non-zero, marks the file as executable. |
356 writefile(Buf *b, char *file) | 356 void |
| 357 writefile(Buf *b, char *file, int exec) |
357 { | 358 { |
358 int fd; | 359 int fd; |
359 ········ | 360 ········ |
360 fd = creat(file, 0666); | 361 fd = creat(file, 0666); |
361 if(fd < 0) | 362 if(fd < 0) |
362 fatal("create %s: %s", file, strerror(errno)); | 363 fatal("create %s: %s", file, strerror(errno)); |
363 if(write(fd, b->p, b->len) != b->len) | 364 if(write(fd, b->p, b->len) != b->len) |
364 fatal("short write: %s", strerror(errno)); | 365 fatal("short write: %s", strerror(errno)); |
| 366 if(exec) |
| 367 fchmod(fd, 0755); |
365 close(fd); | 368 close(fd); |
366 } | 369 } |
367 » | 370 |
368 // xmkdir creates the directory p. | 371 // xmkdir creates the directory p. |
369 void | 372 void |
370 xmkdir(char *p) | 373 xmkdir(char *p) |
371 { | 374 { |
372 if(mkdir(p, 0777) < 0) | 375 if(mkdir(p, 0777) < 0) |
373 fatal("mkdir %s: %s", p, strerror(errno)); | 376 fatal("mkdir %s: %s", p, strerror(errno)); |
374 } | 377 } |
375 | 378 |
376 // xmkdirall creates the directory p and its parents, as needed. | 379 // xmkdirall creates the directory p and its parents, as needed. |
377 void | 380 void |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 708 |
706 // xstrrchr returns a pointer to the final occurrence of c in p. | 709 // xstrrchr returns a pointer to the final occurrence of c in p. |
707 char* | 710 char* |
708 xstrrchr(char *p, int c) | 711 xstrrchr(char *p, int c) |
709 { | 712 { |
710 return strrchr(p, c); | 713 return strrchr(p, c); |
711 } | 714 } |
712 | 715 |
713 #endif // PLAN9 | 716 #endif // PLAN9 |
714 #endif // __WINDOWS__ | 717 #endif // __WINDOWS__ |
LEFT | RIGHT |