# SDL\_RWop::read() file size limit?

**URL:** <https://discourse.libsdl.org/t/sdl-rwop-read-file-size-limit/21129>\
**Category:** SDL Development\
**Created:** [December 19, 2014, 12:15am UTC](https://discourse.libsdl.org/t/sdl-rwop-read-file-size-limit/21129 "2014-12-19T00:15:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![loadRunner](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/5fc32e/32.png) [@loadRunner](https://discourse.libsdl.org/u/loadRunner)\
**Post date:** [December 19, 2014, 12:15am UTC](https://discourse.libsdl.org/t/sdl-rwop-read-file-size-limit/21129/1 "2014-12-19T00:15:33Z")

</div>

Platform: Android

I am trying to read a simple text file with SDL\_RWops::read() file that is 1.7 megs in size. I have successfully read loads of text files already smaller than 500 kb, but my program crashes at that function call with larger files. Is there a file size limit to the function? Is there a work around?

I am on my phone, so can’t properly format the code here, but here is roughly the essential parts:

SDL\_RWops \*io = NULL;  
io =SDL\_RWFromFile(fileName.c\_str(), “r”);

char name[18000000];

if (io != NULL)  
{  
Sint64 seek\_ = SDL\_REdeem(io, 0, RW\_SEEK\_END);  
Sint64 sizeOfFileInBytes = SDL\_RWtell(io);  
seek\_ = SDL\_RWseek(io, 0, RW\_SEEK\_SET);

```
if (io->read(io, name, sizeOfFileInBytes, 1) > 0)
{
    SDL_Log("Failed to Load");
}
io->close(io);

```

}

---

<div class="post-metadata">

**Author:** ![Martin\_Gerhardy](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/martin_gerhardy/32/591_2.png) [@Martin\_Gerhardy](https://discourse.libsdl.org/u/Martin_Gerhardy)\
**Post date:** [January 4, 2015, 7:50am UTC](https://discourse.libsdl.org/t/sdl-rwop-read-file-size-limit/21129/2 "2015-01-04T07:50:14Z")

</div>

Hi,

no, there is no limit, you just didn’t use it correctly. See my code at  
[https://github.com/mgerhardy/caveexpress/blob/master/src/engine/common/File.cpp#L111](https://github.com/mgerhardy/caveexpress/blob/master/src/engine/common/File.cpp#L111)  
for an example how to use it properly. The important part is the return  
value - read does not have to return all the requested bytes, but only  
parts of it.

Regards  
MartinOn Fri, Dec 19, 2014 at 1:15 AM, loadRunner \<game\_maker at [live.com](http://live.com)\> wrote:

> Platform: Android
> 
> I am trying to read a simple text file with SDL\_RWops::read() file that is  
> 1.7 megs in size. I have successfully read loads of text files already  
> smaller than 500 kb, but my program crashes at that function call with  
> larger files. Is there a file size limit to the function? Is there a work  
> around?
> 
> I am on my phone, so can’t properly format the code here, but here is  
> roughly the essential parts:
> 
> SDL\_RWops \*io = NULL;  
> io =SDL\_RWFromFile(fileName.c\_str(), “r”);
> 
> char name[18000000];
> 
> if (io != NULL)  
> {  
> Sint64 seek\_ = SDL\_REdeem(io, 0, RW\_SEEK\_END);  
> Sint64 sizeOfFileInBytes = SDL\_RWtell(io);  
> seek\_ = SDL\_RWseek(io, 0, RW\_SEEK\_SET);
> 
> if (io-\>read(io, name, sizeOfFileInBytes, 1) \> 0)  
> {  
> SDL\_Log(“Failed to Load”);  
> }  
> io-\>close(io);  
> }
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

–  
[http://ufoai.sf.net](http://ufoai.sf.net)

> **[UFO:Alien Invasion](https://sourceforge.net/projects/ufoai)**
>
> Download UFO:Alien Invasion for free. It is the year 2084. You control a secret organisation charged with defending Earth from a brutal alien enemy.
