Lines Matching defs:thefile

28 static apr_status_t file_read_buffered(apr_file_t *thefile, void *buf,
36 if (thefile->direction == 1) {
37 rv = apr_file_flush_locked(thefile);
41 thefile->bufpos = 0;
42 thefile->direction = 0;
43 thefile->dataRead = 0;
47 if (thefile->ungetchar != -1) {
48 *pos = (char)thefile->ungetchar;
51 thefile->ungetchar = -1;
54 if (thefile->bufpos >= thefile->dataRead) {
55 int bytesread = read(thefile->filedes, thefile->buffer,
56 thefile->bufsize);
58 thefile->eof_hit = TRUE;
66 thefile->dataRead = bytesread;
67 thefile->filePtr += thefile->dataRead;
68 thefile->bufpos = 0;
71 blocksize = size > thefile->dataRead - thefile->bufpos ? thefile->dataRead - thefile->bufpos : size;
72 memcpy(pos, thefile->buffer + thefile->bufpos, blocksize);
73 thefile->bufpos += blocksize;
85 APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size_t *nbytes)
95 if (thefile->buffered) {
96 file_lock(thefile);
97 rv = file_read_buffered(thefile, buf, nbytes);
98 file_unlock(thefile);
103 if (thefile->ungetchar != -1) {
105 *(char *)buf = (char)thefile->ungetchar;
108 thefile->ungetchar = -1;
116 rv = read(thefile->filedes, buf, *nbytes);
121 thefile->timeout != 0) {
122 apr_status_t arv = apr_wait_for_io_or_timeout(thefile, NULL, 1);
129 rv = read(thefile->filedes, buf, *nbytes);
136 thefile->eof_hit = TRUE;
147 APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, apr_size_t *nbytes)
151 if (thefile->buffered) {
156 file_lock(thefile);
158 if ( thefile->direction == 0 ) {
162 apr_int64_t offset = thefile->filePtr - thefile->dataRead + thefile->bufpos;
163 if (offset != thefile->filePtr)
164 lseek(thefile->filedes, offset, SEEK_SET);
165 thefile->bufpos = thefile->dataRead = 0;
166 thefile->direction = 1;
171 if (thefile->bufpos == thefile->bufsize) /* write buffer is full*/
172 rv = apr_file_flush_locked(thefile);
174 blocksize = size > thefile->bufsize - thefile->bufpos ?
175 thefile->bufsize - thefile->bufpos : size;
176 memcpy(thefile->buffer + thefile->bufpos, pos, blocksize);
177 thefile->bufpos += blocksize;
182 file_unlock(thefile);
188 rv = write(thefile->filedes, buf, *nbytes);
193 thefile->timeout != 0) {
194 apr_status_t arv = apr_wait_for_io_or_timeout(thefile, NULL, 0);
202 rv = write(thefile->filedes, buf, *nbytes);
226 APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iovec *vec,
233 if (thefile->buffered) {
234 file_lock(thefile);
236 rv = apr_file_flush_locked(thefile);
238 file_unlock(thefile);
241 if (thefile->direction == 0) {
245 apr_int64_t offset = thefile->filePtr - thefile->dataRead +
246 thefile->bufpos;
247 if (offset != thefile->filePtr)
248 lseek(thefile->filedes, offset, SEEK_SET);
249 thefile->bufpos = thefile->dataRead = 0;
252 file_unlock(thefile);
255 if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
280 return apr_file_write(thefile, vec[0].iov_base, nbytes);
284 APR_DECLARE(apr_status_t) apr_file_putc(char ch, apr_file_t *thefile)
288 return apr_file_write(thefile, &ch, &nbytes);
291 APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile)
293 thefile->ungetchar = (unsigned char)ch;
297 APR_DECLARE(apr_status_t) apr_file_getc(char *ch, apr_file_t *thefile)
301 return apr_file_read(thefile, ch, &nbytes);
304 APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile)
306 return apr_file_write_full(thefile, str, strlen(str), NULL);
309 apr_status_t apr_file_flush_locked(apr_file_t *thefile)
313 if (thefile->direction == 1 && thefile->bufpos) {
317 ret = write(thefile->filedes, thefile->buffer + written,
318 thefile->bufpos - written);
321 } while (written < thefile->bufpos &&
326 thefile->filePtr += written;
327 thefile->bufpos = 0;
334 APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile)
338 if (thefile->buffered) {
339 file_lock(thefile);
340 rv = apr_file_flush_locked(thefile);
341 file_unlock(thefile);
349 APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile)
353 file_lock(thefile);
355 if (thefile->buffered) {
356 rv = apr_file_flush_locked(thefile);
359 file_unlock(thefile);
364 if (fsync(thefile->filedes)) {
368 file_unlock(thefile);
373 APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
377 file_lock(thefile);
379 if (thefile->buffered) {
380 rv = apr_file_flush_locked(thefile);
383 file_unlock(thefile);
389 if (fdatasync(thefile->filedes)) {
391 if (fcntl(thefile->filedes, F_FULLFSYNC)) {
393 if (fsync(thefile->filedes)) {
398 file_unlock(thefile);
403 APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
419 if (thefile->buffered) {
420 file_lock(thefile);
422 if (thefile->direction == 1) {
423 rv = apr_file_flush_locked(thefile);
425 file_unlock(thefile);
429 thefile->direction = 0;
430 thefile->bufpos = 0;
431 thefile->dataRead = 0;
436 if (thefile->bufpos < thefile->dataRead &&
437 thefile->ungetchar == -1) {
438 *str = thefile->buffer[thefile->bufpos++];
442 rv = file_read_buffered(thefile, str, &nbytes);
453 file_unlock(thefile);
458 rv = apr_file_read(thefile, str, &nbytes);