|
46 | 46 |
|
47 | 47 | #include <SDL3/SDL_stdinc.h> |
48 | 48 | #include <SDL3/SDL_error.h> |
| 49 | +#include <SDL3/SDL_iostream.h> |
49 | 50 |
|
50 | 51 | #include <SDL3/SDL_begin_code.h> |
51 | 52 |
|
@@ -153,9 +154,10 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetPrefPath(const char *org, const char * |
153 | 154 | /** |
154 | 155 | * The type of the OS-provided default folder for a specific purpose. |
155 | 156 | * |
156 | | - * Note that the Trash folder isn't included here, because trashing files |
157 | | - * usually involves extra OS-specific functionality to remember the file's |
158 | | - * original location. |
| 157 | + * Note that many common folders, like the Trash, the Temp folder or |
| 158 | + * app-specific folders like AppData are not listed here; using them properly |
| 159 | + * requires more treatment than fetching the folder path and using it. To use |
| 160 | + * these folders, see their dedicated functions. |
159 | 161 | * |
160 | 162 | * The folders supported per platform are: |
161 | 163 | * |
@@ -494,6 +496,79 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const ch |
494 | 496 | */ |
495 | 497 | extern SDL_DECLSPEC char * SDLCALL SDL_GetCurrentDirectory(void); |
496 | 498 |
|
| 499 | +/** |
| 500 | + * Create a secure temporary file. |
| 501 | + * |
| 502 | + * This function is not path-based to avoid race conditions. Returning a path |
| 503 | + * and letting the caller create the file opens a time-of-check-to-time-of-use |
| 504 | + * (TOCTOU) safety issue, where an attacker can use the small delay between the |
| 505 | + * moment the name is generated and the moment the file is created to create |
| 506 | + * the file first and give it undesirable attributes, such as giving itself |
| 507 | + * full read/write access to the file, or making the file a symlink to another, |
| 508 | + * sensitive file. |
| 509 | + * |
| 510 | + * \returns an open IOStream object to the file, or NULL on error; call |
| 511 | + * SDL_GetError() for details. |
| 512 | + * |
| 513 | + * \threadsafety It is safe to call this function from any thread. |
| 514 | + * |
| 515 | + * \since This function is available since SDL 3.0.0. |
| 516 | + * |
| 517 | + * \sa SDL_CreateUnsafeTempFile |
| 518 | + * \sa SDL_CreateTempFolder |
| 519 | + */ |
| 520 | +extern SDL_DECLSPEC SDL_IOStream *SDLCALL SDL_CreateSafeTempFile(void); |
| 521 | + |
| 522 | +/** |
| 523 | + * Create a temporary file, with less security considerations. |
| 524 | + * |
| 525 | + * Unlike SDL_CreateSafeTempFile(), this function provides a path, which can |
| 526 | + * then be used like any other file on the filesystem. This has security |
| 527 | + * implications; an attacker could exploit the small delay between the moment |
| 528 | + * the name is generated and the moment the file is created to create the file |
| 529 | + * first and give it undesirable attributes, such as giving itself full |
| 530 | + * read/write access to the file, or making the file a symlink to another, |
| 531 | + * sensitive file. |
| 532 | + * |
| 533 | + * The path string is owned by the caller and must be freed with SDL_free(). |
| 534 | + * |
| 535 | + * \returns an absolute path to the temporary file, or NULL on error; call |
| 536 | + * SDL_GetError() for details. If a path is returned, it is encoded in |
| 537 | + * OS-specific format. |
| 538 | + * |
| 539 | + * \threadsafety It is safe to call this function from any thread. |
| 540 | + * |
| 541 | + * \since This function is available since SDL 3.0.0. |
| 542 | + * |
| 543 | + * \sa SDL_CreateSafeTempFile |
| 544 | + * \sa SDL_CreateTempFolder |
| 545 | + */ |
| 546 | +extern SDL_DECLSPEC char *SDLCALL SDL_CreateUnsafeTempFile(void); |
| 547 | + |
| 548 | +/** |
| 549 | + * Create a temporary folder. |
| 550 | + * |
| 551 | + * Keep in mind any program running as the same user as your program can access |
| 552 | + * the contents of the folders and the files in it. Do not perform sensitive |
| 553 | + * tasks using the temporary folder. If you need one or more temporary files |
| 554 | + * for sensitive purposes, use SDL_CreateSafeTempFile(). |
| 555 | + * |
| 556 | + * The path string is owned by the caller and must be freed with SDL_free(). |
| 557 | + * |
| 558 | + * \returns an absolute path to the temporary folder, or NULL on error; call |
| 559 | + * SDL_GetError() for details. If a path is returned, it is encoded in |
| 560 | + * OS-specific format, and is guaranteed to finish with a path |
| 561 | + * separator. |
| 562 | + * |
| 563 | + * \threadsafety It is safe to call this function from any thread. |
| 564 | + * |
| 565 | + * \since This function is available since SDL 3.0.0. |
| 566 | + * |
| 567 | + * \sa SDL_CreateSafeTempFile |
| 568 | + * \sa SDL_CreateUnsafeTempFile |
| 569 | + */ |
| 570 | +extern SDL_DECLSPEC char *SDLCALL SDL_CreateTempFolder(void); |
| 571 | + |
497 | 572 | /* Ends C function definitions when using C++ */ |
498 | 573 | #ifdef __cplusplus |
499 | 574 | } |
|
0 commit comments