|
30 | 30 |
|
31 | 31 | #include <SDL3/SDL_stdinc.h> |
32 | 32 | #include <SDL3/SDL_error.h> |
| 33 | +#include <SDL3/SDL_iostream.h> |
33 | 34 |
|
34 | 35 | #include <SDL3/SDL_begin_code.h> |
35 | 36 |
|
@@ -137,9 +138,10 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetPrefPath(const char *org, const char * |
137 | 138 | /** |
138 | 139 | * The type of the OS-provided default folder for a specific purpose. |
139 | 140 | * |
140 | | - * Note that the Trash folder isn't included here, because trashing files |
141 | | - * usually involves extra OS-specific functionality to remember the file's |
142 | | - * original location. |
| 141 | + * Note that many common folders, like the Trash, the Temp folder or |
| 142 | + * app-specific folders like AppData are not listed here; using them properly |
| 143 | + * requires more treatment than fetching the folder path and using it. To use |
| 144 | + * these folders, see their dedicated functions. |
143 | 145 | * |
144 | 146 | * The folders supported per platform are: |
145 | 147 | * |
@@ -465,6 +467,80 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const ch |
465 | 467 | */ |
466 | 468 | extern SDL_DECLSPEC char * SDLCALL SDL_GetCurrentDirectory(void); |
467 | 469 |
|
| 470 | +/** |
| 471 | + * Create a secure temporary file. |
| 472 | + * |
| 473 | + * This function is not path-based to avoid race conditions. Returning a path |
| 474 | + * and letting the caller create the file opens a time-of-check-to-time-of-use |
| 475 | + * (TOCTOU) safety issue, where an attacker can use the small delay between the |
| 476 | + * moment the name is generated and the moment the file is created to create |
| 477 | + * the file first and give it undesirable attributes, such as giving itself |
| 478 | + * full read/write access to the file, or making the file a symlink to another, |
| 479 | + * sensitive file. |
| 480 | + * |
| 481 | + * \returns an open IOStream object to the file, or NULL on error; call |
| 482 | + * SDL_GetError() for details. |
| 483 | + * |
| 484 | + * \threadsafety It is safe to call this function from any thread. |
| 485 | + * |
| 486 | + * \since This function is available since SDL 3.0.0. |
| 487 | + * |
| 488 | + * \sa SDL_CreateUnsafeTempFile |
| 489 | + * \sa SDL_CreateTempFolder |
| 490 | + */ |
| 491 | +extern SDL_DECLSPEC SDL_IOStream *SDLCALL SDL_CreateSafeTempFile(void); |
| 492 | + |
| 493 | +/** |
| 494 | + * Create a temporary file, with less security considerations. |
| 495 | + * |
| 496 | + * Unlike SDL_CreateSafeTempFile(), this function provides a path, which can |
| 497 | + * then be used like any other file on the filesystem. This has security |
| 498 | + * implications; an attacker could exploit the small delay between the moment |
| 499 | + * the name is generated and the moment the file is created to create the file |
| 500 | + * first and give it undesirable attributes, such as giving itself full |
| 501 | + * read/write access to the file, or making the file a symlink to another, |
| 502 | + * sensitive file. |
| 503 | + * |
| 504 | + * The path string is owned by the caller and must be freed with SDL_free(). |
| 505 | + * |
| 506 | + * \returns an absolute path to the temporary file, or NULL on error; call |
| 507 | + * SDL_GetError() for details. If a path is returned, it is encoded in |
| 508 | + * OS-specific format, and is guaranteed to finish with a path |
| 509 | + * separator. |
| 510 | + * |
| 511 | + * \threadsafety It is safe to call this function from any thread. |
| 512 | + * |
| 513 | + * \since This function is available since SDL 3.0.0. |
| 514 | + * |
| 515 | + * \sa SDL_CreateSafeTempFile |
| 516 | + * \sa SDL_CreateTempFolder |
| 517 | + */ |
| 518 | +extern SDL_DECLSPEC char *SDLCALL SDL_CreateUnsafeTempFile(void); |
| 519 | + |
| 520 | +/** |
| 521 | + * Create a temporary folder. |
| 522 | + * |
| 523 | + * Keep in mind any program running as the same user as your program can access |
| 524 | + * the contents of the folders and the files in it. Do not perform sensitive |
| 525 | + * tasks using the temporary folder. If you need one or more temporary files |
| 526 | + * for sensitive purposes, use SDL_CreateSafeTempFile(). |
| 527 | + * |
| 528 | + * The path string is owned by the caller and must be freed with SDL_free(). |
| 529 | + * |
| 530 | + * \returns an absolute path to the temporary folder, or NULL on error; call |
| 531 | + * SDL_GetError() for details. If a path is returned, it is encoded in |
| 532 | + * OS-specific format, and is guaranteed to finish with a path |
| 533 | + * separator. |
| 534 | + * |
| 535 | + * \threadsafety It is safe to call this function from any thread. |
| 536 | + * |
| 537 | + * \since This function is available since SDL 3.0.0. |
| 538 | + * |
| 539 | + * \sa SDL_CreateSafeTempFile |
| 540 | + * \sa SDL_CreateUnsafeTempFile |
| 541 | + */ |
| 542 | +extern SDL_DECLSPEC char *SDLCALL SDL_CreateTempFolder(void); |
| 543 | + |
468 | 544 | /* Ends C function definitions when using C++ */ |
469 | 545 | #ifdef __cplusplus |
470 | 546 | } |
|
0 commit comments