mirror of
https://github.com/golang/go
synced 2024-11-23 22:30:05 -07:00
cmd/ld: don't delete output binary if not "ordinary" file.
e.g., don't delete /dev/null. this fix inspired by gnu libiberty, unlink-if-ordinary.c. Fixes #7563 LGTM=iant R=golang-codereviews, iant, 0intro CC=golang-codereviews, r https://golang.org/cl/76810045
This commit is contained in:
parent
2ca99505f6
commit
ece69f7c2b
@ -37,6 +37,9 @@
|
|||||||
#include "../../pkg/runtime/funcdata.h"
|
#include "../../pkg/runtime/funcdata.h"
|
||||||
|
|
||||||
#include <ar.h>
|
#include <ar.h>
|
||||||
|
#if !(defined(_WIN32) || defined(PLAN9))
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -106,8 +109,13 @@ libinit(void)
|
|||||||
// Unix doesn't like it when we write to a running (or, sometimes,
|
// Unix doesn't like it when we write to a running (or, sometimes,
|
||||||
// recently run) binary, so remove the output file before writing it.
|
// recently run) binary, so remove the output file before writing it.
|
||||||
// On Windows 7, remove() can force the following create() to fail.
|
// On Windows 7, remove() can force the following create() to fail.
|
||||||
#ifndef _WIN32
|
// S_ISREG() does not exist on Plan 9.
|
||||||
remove(outfile);
|
#if !(defined(_WIN32) || defined(PLAN9))
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if(lstat(outfile, &st) == 0 && S_ISREG(st.st_mode))
|
||||||
|
remove(outfile);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
cout = create(outfile, 1, 0775);
|
cout = create(outfile, 1, 0775);
|
||||||
if(cout < 0) {
|
if(cout < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user