Was ist das für eine fseek Konstante?



  • Hallo Leute,

    wenn ein Linux Dev diese Zeile schreibt, was meint er dann damit?
    if(fseek(MyFile, MyOffset, SEEK_END-1024))

    In dieser Datei sind die Konstanten des dritten Param aufgeführt:
    http://www.thinkage.ca/english/gcos/expl/c/lib/fseek.html

    Aber was ist dieses SEEK_END-1024?

    Vielen Dank

    Paul



  • Schwarze Paul schrieb:

    Aber was ist dieses SEEK_END-1024?
    Vielen Dank

    Paul

    Das müsste ein undefiniertes Verhalten zur Folge haben, denn laut Referenz sind nur die Werte SEEK_SET, SEEK_CUR und SEEK_END definiert.



  • Ja. Im Visual Studio habe ich da einen Crash. Mit CygwinGCC gehts munter weiter. Also irgendeine Erweiterung der Linux Devs die nicht im Ansi C steht.



  • Schwarze Paul schrieb:

    Ja. Im Visual Studio habe ich da einen Crash. Mit CygwinGCC gehts munter weiter. Also irgendeine Erweiterung der Linux Devs die nicht im Ansi C steht.

    Ist nicht gesagt, kann auch ein Bug in der Implementierung sein, entweder in die Sourcen schauen, oder die Manpages.
    Zumindest unter Linux steht dort:

    FSEEK(3) -- 1993-11-29 -- GNU -- Linux Programmer's Manual

    NAME
    fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream

    SYNOPSIS
    #include <stdio.h>

    int fseek(FILE *stream, long offset, int whence);

    long ftell(FILE *stream);

    void rewind(FILE *stream);

    int fgetpos(FILE *stream, fpos_t *pos);
    int fsetpos(FILE *stream, fpos_t *pos);

    DESCRIPTION
    The fseek() function sets the file position indicator for
    the stream pointed to by stream. The new position, measured
    in bytes, is obtained by adding offset bytes to the position
    specified by whence. If whence is set to SEEK_SET,
    SEEK_CUR, or SEEK_END, the offset is relative to the start
    of the file, the current position indicator, or end-of-file,
    respectively. A successful call to the fseek() function
    clears the end-of-file indicator for the stream and undoes
    any effects of the ungetc(3) function on the same stream.

    The ftell() function obtains the current value of the file
    position indicator for the stream pointed to by stream.

    The rewind() function sets the file position indicator for
    the stream pointed to by stream to the beginning of the
    file. It is equivalent to:

    (void) fseek(stream, 0L, SEEK_SET)

    except that the error indicator for the stream is also
    cleared (see clearerr(3)).

    The fgetpos() and fsetpos() functions are alternate
    interfaces equivalent to ftell() and fseek() (with whence
    set to SEEK_SET), setting and storing the current value of
    the file offset into or from the object referenced by pos.
    On some non-Unix systems an fpos_t object may be a complex
    object and these routines may be the only way to portably
    reposition a text stream.

    RETURN VALUE
    The rewind() function returns no value. Upon successful
    completion, fgetpos(), fseek(), fsetpos() return 0, and
    ftell() returns the current offset. Otherwise, -1 is
    returned and errno is set to indicate the error.

    ERRORS

    EBADF
    The stream specified is not a seekable stream.

    EINVAL
    The whence argument to fseek() was not SEEK_SET,
    SEEK_END, or SEEK_CUR.

    The functions fgetpos(), fseek(), fsetpos(), and ftell() may
    also fail and set errno for any of the errors specified for
    the routines fflush(3), fstat(2), lseek(2), and malloc(3).

    CONFORMING TO
    C89, C99.

    SEE ALSO
    lseek(2), fseeko(3)

    COLOPHON
    This page is part of release 3.21 of the Linux man-pages
    project. A description of the project, and information
    about reporting bugs, can be found at
    http://www.kernel.org/doc/man-pages/.



  • Schwarze Paul schrieb:

    Ja. Im Visual Studio habe ich da einen Crash. Mit CygwinGCC gehts munter weiter. Also irgendeine Erweiterung der Linux Devs die nicht im Ansi C steht.

    Undefiniertes Verhalten bedeutet, dass das Verhalten nicht definiert ist. Also kann das Programm bei einer solchen Konstanten entweder munter weiter laufen oder abstürzen. Beides wiederspricht nicht dem Standard. Also reagieren sowohl Visual Studio als auch CygwinGCC korrekt.



  • Aber von wo nun der Offset losgeht steht da auch nicht. Da muß ich wohl ein paar Feldtests machen...



  • Ich hab mir mal den Draft runtergeladen.

    7.19.9.2 The fseek function
    ...
    Returns
    6 The fseek function returns nonzero only for a request that cannot be satisfied.

    Heißt also, die Zeile
    int ret = fseek(MyFile, MyOffset, SEEK_END-1024);
    müsste einen Wert mit ret != 0 liefert, also Fehler.

    Gruß,
    B.B.



  • Big Brother schrieb:

    Ich hab mir mal den Draft runtergeladen.

    7.19.9.2 The fseek function
    ...
    Returns
    6 The fseek function returns nonzero only for a request that cannot be satisfied.

    Heißt also, die Zeile
    int ret = fseek(MyFile, MyOffset, SEEK_END-1024);
    müsste einen Wert mit ret != 0 liefert, also Fehler.

    Gruß,
    B.B.

    Zumindest in dem Zitat von dir steht aber nicht was "cannot be satisfied" bedeutet, wenn der CygwinGCC das irgendwie sinnvoll verarbeiten kann, dann kann er wohl auch 0 zurückliefern. Aber wie oben schon gesagt dafür sind die Manpages da (und damit meine ich nicht die POSIX Manpages sondern die implementierungsspezifischen Manpages), da stehen alle Eigenheiten der jeweiligen Implementierung drin.



  • Schwarze Paul schrieb:

    Aber von wo nun der Offset losgeht steht da auch nicht. Da muß ich wohl ein paar Feldtests machen...

    Keine Feldtests bitte. Ausprobieren hilft nicht. Wenn ein Linux Dev das schreibt, dann ist das einfach nur falsch und sollte schnellstens vergessen werden. Es ist einfach uninteressant, wie ein Programm falsch läuft. Es ist einfach nur egal, ob ein Fehlercode oder ein Absturz passiert. Es ist falsch falsch falsch.


Anmelden zum Antworten