Changeset 1c7f381 in mainline


Ignore:
Timestamp:
2018-01-22T20:12:00Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e0f47f5
Parents:
df2e5514
Message:

Add nonstandard ftell64() and fseek64().

Currently, the C standard does not define any functions that can access file
offset with full 64-bit range. Standard ftell()/fseek() are nonportable on files
over 2 GB, while fgetpos()/fsetpos() can work with arbitrary length file, but
keep the position opaque, and no cannot be used for seeks to known numerical
offsets.

POSIX defines ftello()/fseeko(), which _can_ be 64-bit, but aren't guaranteed
to be by the standard, and come with additional baggage. Also, the naming
is rather awkward.

In short, there is no portable interface for this functionality, so
a pair of nonstandard functions is an adequate answer for this.

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/io.c

    rdf2e5514 r1c7f381  
    799799}
    800800
    801 int fseek(FILE *stream, long offset, int whence)
     801int fseek64(FILE *stream, off64_t offset, int whence)
    802802{
    803803        errno_t rc;
     
    837837}
    838838
    839 long ftell(FILE *stream)
    840 {
    841         /* The native position is too large for the C99-ish interface. */
    842         if (stream->pos - stream->ungetc_chars > LONG_MAX)
    843                 return EOF;
    844 
     839off64_t ftell64(FILE *stream)
     840{
    845841        if (stream->error)
    846842                return EOF;
     
    853849
    854850        return stream->pos - stream->ungetc_chars;
     851}
     852
     853int fseek(FILE *stream, long offset, int whence)
     854{
     855        return fseek64(stream, offset, whence);
     856}
     857
     858long ftell(FILE *stream)
     859{
     860        off64_t off = ftell64(stream);
     861
     862        /* The native position is too large for the C99-ish interface. */
     863        if (off > LONG_MAX)
     864                return EOF;
     865
     866        return off;
    855867}
    856868
  • uspace/lib/c/include/stdio.h

    rdf2e5514 r1c7f381  
    158158extern char *gets(char *, size_t);
    159159
     160#include <offset.h>
     161
     162extern int fseek64(FILE *, off64_t, int);
     163extern off64_t ftell64(FILE *);
     164
    160165#endif
    161166
Note: See TracChangeset for help on using the changeset viewer.