+2004-02-22 Jakub Jelinek <jakub@redhat.com>
+
+ * 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 <kazu@cs.umass.edu>
* reorg.c: Remove comments about dead ports.
#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. */
#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}"
#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}"
#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}"
#endif
#if GCOV_LOCKED
struct flock s_flock;
+ int fd;
s_flock.l_type = F_WRLCK;
s_flock.l_whence = SEEK_SET;
#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)
}
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;
}
#if GCOV_LOCKED
#include <fcntl.h>
#include <errno.h>
+#include <sys/stat.h>
#endif
#ifdef L_gcov