このページを編集する際は,編集に関する方針に従ってください.[]
概要[]
- gcc-4.1.0/gcc/gcov-io.c, gcc-4.1.0/gcc/gcov-io.hにて定義
- ファイルを開き、gcov_varの初期化をする
引数[]
- const char */*name*/
- (int /*direction*/)
実装[]
== *gcc-4.1.0/gcc/gcov-io.h ==
228 /* In gcov we want function linkage to be static. In the compiler we want
229 it extern, so that they can be accessed from elsewhere. In libgcov we
230 need these functions to be extern, so prefix them with __gcov. In
231 libgcov they must also be hidden so that the instance in the executable
232 is not also used in a DSO. */
233 #if IN_LIBGCOV
~
238 #define gcov_open __gcov_open
== *gcc-4.1.0/gcc/gcov-io.c ==
48 /* Open a gcov file. NAME is the name of the file to open and MODE
49 indicates whether a new file should be created, or an existing file
50 opened for modification. If MODE is >= 0 an existing file will be
51 opened, if possible, and if MODE is <= 0, a new file will be
52 created. Use MODE=0 to attempt to reopen an existing file and then
53 fall back on creating a new one. Return zero on failure, >0 on
54 opening an existing file and <0 on creating a new one. */
55
56 GCOV_LINKAGE int
57 #if IN_LIBGCOV
58 gcov_open (const char *name)
59 #else
60 gcov_open (const char *name, int mode)
61 #endif
62 {
63 #if IN_LIBGCOV
64 const int mode = 0;
65 #endif
~
66 #if GCOV_LOCKED
67 struct flock s_flock;
68 int fd;
69
70 s_flock.l_type = F_WRLCK;
71 s_flock.l_whence = SEEK_SET;
72 s_flock.l_start = 0;
73 s_flock.l_len = 0; /* Until EOF. */
74 s_flock.l_pid = getpid ();
75 #endif
76
~
*gcov_varの初期化
77 gcc_assert (!gcov_var.file);
78 gcov_var.start = 0;
79 gcov_var.offset = gcov_var.length = 0;
80 gcov_var.overread = -1u;
81 gcov_var.error = 0;
82 #if !IN_LIBGCOV
83 gcov_var.endian = 0;
84 #endif
~
*ファイルを開く
85 #if GCOV_LOCKED
86 if (mode > 0)
87 fd = open (name, O_RDWR);
88 else
89 fd = open (name, O_RDWR | O_CREAT, 0666);
90 if (fd < 0)
91 return 0;
92
93 while (fcntl (fd, F_SETLKW, &s_flock) && errno == EINTR)
94 continue;
95
96 gcov_var.file = fdopen (fd, "r+b");
97 if (!gcov_var.file)
98 {
99 close (fd);
100 return 0;
101 }
102
103 if (mode > 0)
104 gcov_var.mode = 1;
105 else if (mode == 0)
106 {
107 struct stat st;
108
109 if (fstat (fd, &st) < 0)
110 {
111 fclose (gcov_var.file);
112 gcov_var.file = 0;
113 return 0;
114 }
115 if (st.st_size != 0)
116 gcov_var.mode = 1;
117 else
118 gcov_var.mode = mode * 2 + 1;
119 }
120 else
121 gcov_var.mode = mode * 2 + 1;
122 #else
123 if (mode >= 0)
124 gcov_var.file = fopen (name, "r+b");
125 if (gcov_var.file)
126 gcov_var.mode = 1;
127 else if (mode <= 0)
128 {
129 gcov_var.file = fopen (name, "w+b");
130 if (gcov_var.file)
131 gcov_var.mode = mode * 2 + 1;
132 }
133 if (!gcov_var.file)
134 return 0;
135 #endif
136
~
*バッファリングしない
137 setbuf (gcov_var.file, (char *)0);
138
139 return 1;
140 }