The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 The Android Open Source Project |
| 2 | ** |
| 3 | ** This software is licensed under the terms of the GNU General Public |
| 4 | ** License version 2, as published by the Free Software Foundation, and |
| 5 | ** may be copied, distributed, and modified under those terms. |
| 6 | ** |
| 7 | ** This program is distributed in the hope that it will be useful, |
| 8 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | ** GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _ANDROID_UTILS_TEMPFILE_H |
| 14 | #define _ANDROID_UTILS_TEMPFILE_H |
| 15 | |
| 16 | /** TEMP FILE SUPPORT |
| 17 | ** |
| 18 | ** simple interface to create an empty temporary file on the system. |
| 19 | ** |
| 20 | ** create the file with tempfile_create(), which returns a reference to a TempFile |
| 21 | ** object, or NULL if your system is so weird it doesn't have a temporary directory. |
| 22 | ** |
| 23 | ** you can then call tempfile_path() to retrieve the TempFile's real path to open |
| 24 | ** it. the returned path is owned by the TempFile object and should not be freed. |
| 25 | ** |
| 26 | ** all temporary files are destroyed when the program quits, unless you explicitely |
| 27 | ** close them before that with tempfile_close() |
| 28 | **/ |
| 29 | |
| 30 | typedef struct TempFile TempFile; |
| 31 | |
| 32 | extern TempFile* tempfile_create( void ); |
| 33 | extern const char* tempfile_path( TempFile* temp ); |
| 34 | extern void tempfile_close( TempFile* temp ); |
| 35 | |
| 36 | /** TEMP FILE CLEANUP |
| 37 | ** |
| 38 | ** We delete all temporary files in atexit()-registered callbacks. |
| 39 | ** however, the Win32 DeleteFile is unable to remove a file unless |
| 40 | ** all HANDLEs to it are closed in the terminating process. |
| 41 | ** |
| 42 | ** Call 'atexit_close_fd' on a newly open-ed file descriptor to indicate |
| 43 | ** that you want it closed in atexit() time. You should always call |
| 44 | ** this function unless you're certain that the corresponding file |
| 45 | ** cannot be temporary. |
| 46 | ** |
| 47 | ** Call 'atexit_close_fd_remove' before explicitely closing a 'fd' |
| 48 | **/ |
| 49 | extern void atexit_close_fd(int fd); |
| 50 | extern void atexit_close_fd_remove(int fd); |
| 51 | |
| 52 | #endif /* _ANDROID_UTILS_TEMPFILE_H */ |