mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
parent
c3ed8d6c7f
commit
d769df3482
17 changed files with 102 additions and 155 deletions
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
@ -25,6 +26,23 @@
|
|||
* @param stream is a non-null stream handle
|
||||
* @returns current byte offset from beginning of file, or -1
|
||||
*/
|
||||
long ftell(FILE *stream) {
|
||||
return fseek(stream, 0, SEEK_CUR);
|
||||
long ftell(FILE *f) {
|
||||
int64_t pos;
|
||||
if (f->fd != -1) {
|
||||
if (f->beg && !f->end) {
|
||||
f->writer(f);
|
||||
}
|
||||
if ((pos = lseek(f->fd, 0, SEEK_CUR)) != -1) {
|
||||
f->state = 0;
|
||||
f->beg = 0;
|
||||
f->end = 0;
|
||||
return pos;
|
||||
} else {
|
||||
f->state = errno == ESPIPE ? EBADF : errno;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
errno = f->state;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue