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 30typedef struct TempFile TempFile; 31 32extern TempFile* tempfile_create( void ); 33extern const char* tempfile_path( TempFile* temp ); 34extern 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 **/ 49extern void atexit_close_fd(int fd); 50extern void atexit_close_fd_remove(int fd); 51 52#endif /* _ANDROID_UTILS_TEMPFILE_H */ 53