Home | History | Annotate | Download | only in utils
      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 #include "android/utils/compiler.h"
     17 
     18 ANDROID_BEGIN_HEADER
     19 
     20 /** TEMP FILE SUPPORT
     21  **
     22  ** simple interface to create an empty temporary file on the system.
     23  **
     24  ** create the file with tempfile_create(), which returns a reference to a TempFile
     25  ** object, or NULL if your system is so weird it doesn't have a temporary directory.
     26  **
     27  ** you can then call tempfile_path() to retrieve the TempFile's real path to open
     28  ** it. the returned path is owned by the TempFile object and should not be freed.
     29  **
     30  ** all temporary files are destroyed when the program quits, unless you explicitely
     31  ** close them before that with tempfile_close()
     32  **/
     33 
     34 typedef struct TempFile   TempFile;
     35 
     36 extern  TempFile*    tempfile_create( void );
     37 extern  const char*  tempfile_path( TempFile*  temp );
     38 extern  void         tempfile_close( TempFile*  temp );
     39 
     40 /** TEMP FILE CLEANUP
     41  **
     42  ** We delete all temporary files in atexit()-registered callbacks.
     43  ** however, the Win32 DeleteFile is unable to remove a file unless
     44  ** all HANDLEs to it are closed in the terminating process.
     45  **
     46  ** Call 'atexit_close_fd' on a newly open-ed file descriptor to indicate
     47  ** that you want it closed in atexit() time. You should always call
     48  ** this function unless you're certain that the corresponding file
     49  ** cannot be temporary.
     50  **
     51  ** Call 'atexit_close_fd_remove' before explicitely closing a 'fd'
     52  **/
     53 extern void          atexit_close_fd(int  fd);
     54 extern void          atexit_close_fd_remove(int  fd);
     55 
     56 ANDROID_END_HEADER
     57 
     58 #endif /* _ANDROID_UTILS_TEMPFILE_H */
     59