| 150 | } |
| 151 | |
| 152 | static void test_fseek(int buflen) |
| 153 | { |
| 154 | ACL_VSTREAM *fp; |
| 155 | ACL_VSTRING *why = acl_vstring_alloc(100); |
| 156 | char filename[] ="./tmp.txt"; |
| 157 | char buf[10]; |
| 158 | int n; |
| 159 | int offset, off2; |
| 160 | int ch; |
| 161 | |
| 162 | fp = acl_safe_open(filename, O_CREAT | O_RDWR, 0600, |
| 163 | (struct stat *) 0, (uid_t)-1, |
| 164 | (uid_t )-1, why); |
| 165 | if (fp == 0) |
| 166 | acl_msg_fatal("%s(%d)->%s: can't open %s, serr = %s", |
| 167 | __FILE__, __LINE__, __FUNCTION__, filename, acl_vstring_str(why)); |
| 168 | |
| 169 | fp->read_buf_len = buflen; |
| 170 | |
| 171 | ch = acl_vstream_getc(fp); |
| 172 | printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n", |
| 173 | __LINE__, ch, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset); |
| 174 | offset = acl_vstream_fseek(fp, 0, SEEK_CUR); |
| 175 | printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, offset=%d, %d\n\n", |
| 176 | __LINE__, ch, (int) fp->read_cnt, offset, (int) fp->offset, (int) fp->sys_offset); |
| 177 | |
| 178 | ch = acl_vstream_getc(fp); |
| 179 | printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n", |
| 180 | __LINE__, ch, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset); |
| 181 | offset = acl_vstream_fseek(fp, 0, SEEK_CUR); |
| 182 | printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, %s, offset=%d, %d\n\n", |
| 183 | __LINE__, ch, (int) fp->read_cnt, offset, strerror(errno), (int) fp->offset, (int) fp->sys_offset); |
| 184 | |
| 185 | offset = acl_vstream_fseek(fp, 10, SEEK_CUR); |
| 186 | off2 = lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR); |
| 187 | printf("after fseek(10)(%d) >>> off=%d, %d, lseek = %d, read_cnt = %d, offset=%d, %d\n\n", |
| 188 | __LINE__, offset, (int) fp->sys_offset, off2, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset); |
| 189 | |
| 190 | n = acl_vstream_gets(fp, buf, sizeof(buf) - 1); |
| 191 | printf("after read(getline)(%d) >>> buf = [%s], n = %d, fp->read_cnt = %d, offset=%d, %d, lseek=%d\n", |
| 192 | __LINE__, buf, n, (int) fp->read_cnt, (int) fp->offset, (int)fp->sys_offset, |
| 193 | (int) lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR)); |
| 194 | offset = acl_vstream_fseek(fp, 0, SEEK_CUR); |
| 195 | printf("after fseek(0)(%d) >>> buf = [%s], read_cnt = %d, off = %d, %d, offset=%d, %d\n\n", |
| 196 | __LINE__, buf, (int) fp->read_cnt, offset, (int) lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR), |
| 197 | (int) fp->offset, (int) fp->sys_offset); |
| 198 | |
| 199 | ch = acl_vstream_getc(fp); |
| 200 | printf("after read(1)(%d) >>> ch = %c, read_cnt = %d, offset=%d, %d\n", |
| 201 | __LINE__, ch, (int) fp->read_cnt, (int) fp->offset, (int) fp->sys_offset); |
| 202 | offset = acl_vstream_fseek(fp, 0, SEEK_CUR); |
| 203 | printf("after fseek(0)(%d) >>> ch = %c, read_cnt = %d, off = %d, %d, offset=%d, %d\n\n", |
| 204 | __LINE__, ch, (int) fp->read_cnt, offset, (int) lseek(ACL_VSTREAM_FILE(fp), 0, SEEK_CUR), |
| 205 | (int) fp->offset, (int) fp->sys_offset); |
| 206 | |
| 207 | n = acl_vstream_readn(fp, buf, 2); |
| 208 | buf[n] = 0; |
| 209 | printf("after read(buf)(%d) >>> buf = [%s], fp->read_cnt = %d, offset=%d, %d\n", |
no test coverage detected
searching dependent graphs…