From: Jakub Jelinek Date: Sun, 22 Feb 2004 23:18:53 +0000 (+0100) Subject: gcov-io.c (gcov_open): Use open + fdopen instead of fopen. X-Git-Tag: releases/gcc-4.0.0~9930 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2cd64b5a9c4f557553b00482216117d05200a93;p=thirdparty%2Fgcc.git gcov-io.c (gcov_open): Use open + fdopen instead of fopen. * 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. From-SVN: r78281 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e0d0323ff4e5..9e18f300bdec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2004-02-22 Jakub Jelinek + + * 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. + 2004-02-22 Kazu Hirata * reorg.c: Remove comments about dead ports. diff --git a/gcc/config/rs6000/linux.h b/gcc/config/rs6000/linux.h index 1ef484e629dd..8fe3e3e87edb 100644 --- a/gcc/config/rs6000/linux.h +++ b/gcc/config/rs6000/linux.h @@ -91,6 +91,8 @@ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack +#define TARGET_HAS_F_SETLKW + /* Do code reading to identify a signal frame, and set the frame state data appropriately. See unwind-dw2.c for the structs. */ diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index 44f7cb72a558..ee381858223b 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -543,6 +543,8 @@ while (0) #define TARGET_ASM_FILE_END file_end_indicate_exec_stack +#define TARGET_HAS_F_SETLKW + #define LINK_GCC_C_SEQUENCE_SPEC \ "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}" diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h index afec8aab37f7..187dff6eee86 100644 --- a/gcc/config/sparc/linux.h +++ b/gcc/config/sparc/linux.h @@ -247,6 +247,8 @@ do { \ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack +#define TARGET_HAS_F_SETLKW + #undef LINK_GCC_C_SEQUENCE_SPEC #define LINK_GCC_C_SEQUENCE_SPEC \ "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}" diff --git a/gcc/config/sparc/linux64.h b/gcc/config/sparc/linux64.h index 9bfb9462c1ec..5cb84e5f9169 100644 --- a/gcc/config/sparc/linux64.h +++ b/gcc/config/sparc/linux64.h @@ -325,6 +325,8 @@ do { \ #define TARGET_ASM_FILE_END file_end_indicate_exec_stack +#define TARGET_HAS_F_SETLKW + #undef LINK_GCC_C_SEQUENCE_SPEC #define LINK_GCC_C_SEQUENCE_SPEC \ "%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}" diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 99731f79939e..0349fb821b21 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; } diff --git a/gcc/libgcov.c b/gcc/libgcov.c index ffc3d54752c5..d5c97a2854d6 100644 --- a/gcc/libgcov.c +++ b/gcc/libgcov.c @@ -79,6 +79,7 @@ void __gcov_merge_delta (gcov_type *counters __attribute__ ((unused)), #if GCOV_LOCKED #include #include +#include #endif #ifdef L_gcov