Issue with that line - should set current position at the begining, but set at the end of the file !!! #1

Closed
opened 2022-05-03 22:26:44 +02:00 by Slyvtt · 3 comments
Owner

a87c39daa8/IMG.c (L165)

That line causes a lot of troubles. seems there is a problem as it should set the current position in the file at the very begining but in fact set it at the very end.

https://gitea.planet-casio.com/Slyvtt/cSDL_image1_2_12/src/commit/a87c39daa8fa9a6dda3b0b4ba3e7e75eaeb8d469/IMG.c#L165 That line causes a lot of troubles. seems there is a problem as it should set the current position in the file at the very begining but in fact set it at the very end.

Yes, of course. See what's happening:

You start here:

	long temp = SDL_RWseek(src, 0, RW_SEEK_CUR);

That call is defined here, which sounds nice:

#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)

But what is RW_SEEK_CUR exactly? Since we're using the stdio backend, this should be SEEK_CUR from <stdio.h>. But no, it's defined here, as a constant:

#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 */

And what would you know, that's not the convention used by fxlibc, which is instead defined here:

#define SEEK_CUR 0
#define SEEK_END 1
#define SEEK_SET 2

Just fix the SDL source to use SEEK_SET, SEEK_CUR and SEEK_END from <stdio.h> and, if my analysis is correct, you'll get there in no time.

Yes, of course. See what's happening: You start [here](https://gitea.planet-casio.com/Slyvtt/cSDL_image1_2_12/src/commit/a87c39daa8fa9a6dda3b0b4ba3e7e75eaeb8d469/IMG.c#L165): ``` long temp = SDL_RWseek(src, 0, RW_SEEK_CUR); ``` That call is defined [here](https://gitea.planet-casio.com/Slyvtt/cSDL1_2_15/src/branch/master/include/SDL/SDL_rwops.h#L122), which sounds nice: ``` #define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence) ``` But what is `RW_SEEK_CUR` exactly? Since we're using the stdio backend, this should be `SEEK_CUR` from `<stdio.h>`. But no, it's defined [here](https://gitea.planet-casio.com/Slyvtt/cSDL1_2_15/src/branch/master/include/SDL/SDL_rwops.h#L115-L117), as a constant: ``` #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 */ ``` And what would you know, that's not the convention used by fxlibc, which is instead defined [here](https://gitea.planet-casio.com/Vhex-Kernel-Core/fxlibc/src/branch/master/include/stdio.h#L128-L130): ``` #define SEEK_CUR 0 #define SEEK_END 1 #define SEEK_SET 2 ``` Just fix the SDL source to use `SEEK_SET`, `SEEK_CUR` and `SEEK_END` from `<stdio.h>` and, if my analysis is correct, you'll get there in no time.
Author
Owner

Correct, I checked everything except that, and it is so obvious !! Thanks Lephé, I was getting mad. Will try asap.

Correct, I checked everything except that, and it is so obvious !! Thanks Lephé, I was getting mad. Will try asap.
Author
Owner

Issue solved / Closing the ticket. Thx

Issue solved / Closing the ticket. Thx
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Slyvtt/cSDL_image#1
No description provided.