|
Size: 2423
Comment: Changed signature to match SDL_main.h.
|
Size: 1693
Comment: Rewritten.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| ||<tablewidth="100%" style="color: #FF0000;" :> DRAFT|| | |
| Line 6: | Line 5: |
| Use this function to write to a data stream ''-or-'' *call the write function in an SDL_RWops structure.* | Use this function to write to a data stream. |
| Line 19: | Line 18: |
| ||'''context'''||an SDL_RWops structure ^containing the write function^|| ||'''ptr'''||*a pointer to an area in memory to read data from*|| ||'''size'''||*the size of the memory blocks to write*|| ||'''num'''||*the exact number of memory blocks to write*|| |
||'''context'''||a pointer to an SDL_RWops structure|| ||'''ptr'''||a pointer to a buffer containing data to write|| ||'''size'''||the size of an object to write, in bytes|| ||'''num'''||the number of objects to write|| |
| Line 25: | Line 24: |
| Returns the number of objects written, or 0 at error or end of file; call [[SDL_GetError]]() for more information. ''-or-'' *>>On success,>> ,,it ,,returns the number of memory blocks you told it to write >> >>. If it couldn't write that exact number of blocks, or the write didn't work at all, it returns ,,-1,, ^a negative error code^*; call [[SDL_GetError]]() for more information. |
Returns the number of objects written, which will be less than '''num''' on error; call [[SDL_GetError]]() for more information. |
| Line 32: | Line 27: |
| * | |
| Line 34: | Line 28: |
| #include <stdio.h> #include <string.h> #include "SDL_rwops.h" int main(int argc, char *argv[]) { int written; char *str="Hello World"; SDL_RWops *rw=SDL_RWFromFile("test.bin","wb"); if(rw==NULL) { fprintf(stderr,"Couldn't open test.bin\n"); return(1); } written=SDL_RWwrite(rw,str,1,strlen(str)); SDL_RWclose(rw); if(written<0) { fprintf(stderr,"Couldn't write to test.bin\n"); return(2); } fprintf(stderr,"Wrote %d 1-byte blocks\n",written); return(0); |
SDL_RWops *rw = SDL_RWFromFile("hello.txt", "w"); if(rw != NULL) { const char *str = "Hello World"; size_t len = SDL_strlen(str); if (SDL_RWwrite(rw, str, 1, len) != len) { printf("Couldn't fully write string\n"); } else { printf("Wrote %d 1-byte blocks\n", len); } SDL_RWclose(rw); |
| Line 62: | Line 40: |
| * | |
| Line 65: | Line 42: |
| *<<BR>>This is not a built-in function. This is a macro that calls whatever write function happens to be in the SDL_RWops structure.<<BR>>* | This function writes exactly '''num''' objects each of size '''size''' from the area pointed at by '''ptr''' to the stream. If this fails for any reason, it'll return less than '''num''' to demonstrate how far the write progressed. On success, it returns '''num'''. |
| Line 67: | Line 44: |
| [[SDL_RWwrite]] writes exactly '''num''' objects each of size '''size''' from the area pointed at by '''ptr''' to data ,,source,, ^stream^. <<Color2(green,Should SDL_RWwrite have () like a function even though it's a macro?)>> | SDL_RWwrite is actually a macro that calls the SDL_RWops's '''write''' method appropriately, to simplify application development. |
| Line 70: | Line 47: |
| .[[SDL_RWclose]] (Macro) * .[[SDL_RWFromFile]] * .[[SDL_RWread]] (Macro) * .[[SDL_RWseek]](Macro) * <<Color2(green,Should the current read and write functions (not macros) be listed?)>> |
.[[SDL_RWclose]] .[[SDL_RWread]] .[[SDL_RWseek]] |
SDL_RWwrite
Use this function to write to a data stream.
Contents
Syntax
size_t SDL_RWwrite(struct SDL_RWops* context,
const void* ptr,
size_t size,
size_t num)
Function Parameters
context |
a pointer to an SDL_RWops structure |
ptr |
a pointer to a buffer containing data to write |
size |
the size of an object to write, in bytes |
num |
the number of objects to write |
Return Value
Returns the number of objects written, which will be less than num on error; call SDL_GetError() for more information.
Code Examples
SDL_RWops *rw = SDL_RWFromFile("hello.txt", "w");
if(rw != NULL) {
const char *str = "Hello World";
size_t len = SDL_strlen(str);
if (SDL_RWwrite(rw, str, 1, len) != len) {
printf("Couldn't fully write string\n");
} else {
printf("Wrote %d 1-byte blocks\n", len);
}
SDL_RWclose(rw);
}
Remarks
This function writes exactly num objects each of size size from the area pointed at by ptr to the stream. If this fails for any reason, it'll return less than num to demonstrate how far the write progressed. On success, it returns num.
SDL_RWwrite is actually a macro that calls the SDL_RWops's write method appropriately, to simplify application development.
