| 3774 | } |
| 3775 | |
| 3776 | static long ftell(FILE *stream) |
| 3777 | { |
| 3778 | long result = -1, offset = 0; |
| 3779 | stdio_lock(stream, -1); |
| 3780 | if (stream->flags & STDIO_FLAG_READING) |
| 3781 | { |
| 3782 | offset = -(stream->read_end - stream->read_ptr); |
| 3783 | offset -= (stream->unget != EOF? 1: 0); |
| 3784 | } |
| 3785 | else if (stream->flags & STDIO_FLAG_WRITING) |
| 3786 | offset = stream->write_ptr - stream->buf; |
| 3787 | result = lseek(stream->fd, 0, SEEK_CUR); |
| 3788 | if (result >= 0) |
| 3789 | result += offset; |
| 3790 | stdio_unlock(stream); |
| 3791 | return result; |
| 3792 | } |
| 3793 | |
| 3794 | /****************************************************************************/ |
| 3795 | /* PRINTF */ |