diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-22 23:18:53 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-22 23:18:53 +0000 |
commit | 9131ff41bb32de9bb320edc3116f8f6b53dbae6a (patch) | |
tree | 6c2966c9e874f2bcf465ee81f2abd1e32d6b4d12 /gcc/gcov-io.c | |
parent | ea1d1c38832bfcde3644908d3dbd8f94f578669e (diff) | |
download | gcc-9131ff41bb32de9bb320edc3116f8f6b53dbae6a.tar.gz |
* gcov-io.c (gcov_open) [GCOV_LOCKED]: Use open + fdopen instead of
fopen.
* libgcov.c: Include sys/stat.h.
* config/rs6000/linux.h (TARGET_HAS_F_SETLKW): Define.
* config/rs6000/linux64.h (TARGET_HAS_F_SETLKW): Define.
* config/sparc/linux.h (TARGET_HAS_F_SETLKW): Define.
* config/sparc/linux64.h (TARGET_HAS_F_SETLKW): Define.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@78281 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gcov-io.c')
-rw-r--r-- | gcc/gcov-io.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 99731f79939..0349fb821b2 100644 --- a/gcc/gcov-io.c +++ b/gcc/gcov-io.c @@ -65,6 +65,7 @@ gcov_open (const char *name, int mode) #endif #if GCOV_LOCKED struct flock s_flock; + int fd; s_flock.l_type = F_WRLCK; s_flock.l_whence = SEEK_SET; @@ -82,6 +83,44 @@ gcov_open (const char *name, int mode) #if !IN_LIBGCOV gcov_var.endian = 0; #endif +#if GCOV_LOCKED + if (mode > 0) + fd = open (name, O_RDWR); + else + fd = open (name, O_RDWR | O_CREAT, 0666); + if (fd < 0) + return 0; + + while (fcntl (fd, F_SETLKW, &s_flock) && errno == EINTR) + continue; + + gcov_var.file = fdopen (fd, "r+b"); + if (!gcov_var.file) + { + close (fd); + return 0; + } + + if (mode > 0) + gcov_var.mode = 1; + else if (mode == 0) + { + struct stat st; + + if (fstat (fd, &st) < 0) + { + fclose (gcov_var.file); + gcov_var.file = 0; + return 0; + } + if (st.st_size != 0) + gcov_var.mode = 1; + else + gcov_var.mode = mode * 2 + 1; + } + else + gcov_var.mode = mode * 2 + 1; +#else if (mode >= 0) gcov_var.file = fopen (name, "r+b"); if (gcov_var.file) @@ -94,15 +133,10 @@ gcov_open (const char *name, int mode) } if (!gcov_var.file) return 0; - - setbuf (gcov_var.file, (char *)0); - -#if GCOV_LOCKED - while (fcntl (fileno (gcov_var.file), F_SETLKW, &s_flock) - && errno == EINTR) - continue; #endif + setbuf (gcov_var.file, (char *)0); + return 1; } |