We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4820 - SDL assumes RW_SEEK_SET == SEEK_SET
Summary: SDL assumes RW_SEEK_SET == SEEK_SET
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: file (show other bugs)
Version: HG 2.1
Hardware: All Other
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-08 14:19 UTC by Dan Gohman
Modified: 2019-10-10 15:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Gohman 2019-10-08 14:19:15 UTC
SDL defines its own constants for RW_SEEK_SET etc., and then assumes that they have the same values as the host SEEK_SET etc. However, while the values SDL uses are common, they are not universal; for example cloudlibc uses different values:

https://github.com/NuxiNL/cloudlibc/blob/master/src/include/stdio.h#L88

Specifically, include/SDL_rwops.h defines RW_SEEK_SET etc. like this:

#define RW_SEEK_SET 0       /**< Seek from the beginning of data */
#define RW_SEEK_CUR 1       /**< Seek relative to current read point */
#define RW_SEEK_END 2       /**< Seek relative to the end of data */

http://hg.libsdl.org/SDL/file/db9d0d0b7ebc/include/SDL_rwops.h#l174

And then passes them to the host fseek:

http://hg.libsdl.org/SDL/file/db9d0d0b7ebc/src/file/SDL_rwops.c#l370

Ideally, SDL should remap RW_SEEK_SET etc. to SEEK_SET etc., which compilers would likely be able to optimize away on hosts where they are the same.
Comment 1 Sylvain 2019-10-10 15:25:55 UTC
Thanks, 
Fixed https://hg.libsdl.org/SDL/rev/efa5fe44e4e8

(done the same way as window_seek, mem_seek, etc..)


Just notice, since linux 3.1, there are also: SEEK_DATA, SEEK_HOLE ...
that would have worked before, but I am not seek this is used.
I think not in SDL_mixer/ttf/image externals libs

  Seeking file data and holes
       Since version 3.1, Linux supports the following additional values for
       whence:

       SEEK_DATA
              Adjust the file offset to the next location in the file
              greater than or equal to offset containing data.  If offset
              points to data, then the file offset is set to offset.

       SEEK_HOLE
              Adjust the file offset to the next hole in the file greater
              than or equal to offset.  If offset points into the middle of
              a hole, then the file offset is set to offset.  If there is no
              hole past offset, then the file offset is adjusted to the end
              of the file (i.e., there is an implicit hole at the end of any
              file).

http://man7.org/linux/man-pages/man2/lseek.2.html