Home | History | Annotate | Download | only in deutil
      1 #ifndef _DEFILE_H
      2 #define _DEFILE_H
      3 /*-------------------------------------------------------------------------
      4  * drawElements Utility Library
      5  * ----------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief File abstraction.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "deDefs.h"
     27 
     28 DE_BEGIN_EXTERN_C
     29 
     30 /* File types. */
     31 typedef struct deFile_s deFile;
     32 
     33 typedef enum deFileMode_e
     34 {
     35 	DE_FILEMODE_READ		= (1<<0),	/*!< Read access to file.											*/
     36 	DE_FILEMODE_WRITE		= (1<<2),	/*!< Write access to file.											*/
     37 	DE_FILEMODE_CREATE		= (1<<3),	/*!< Create file if it doesn't exist. Requires DE_FILEMODE_WRITE.	*/
     38 	DE_FILEMODE_OPEN		= (1<<4),	/*!< Open file if it exists.										*/
     39 	DE_FILEMODE_TRUNCATE	= (1<<5)	/*!< Truncate content of file. Requires DE_FILEMODE_OPEN.			*/
     40 } deFileMode;
     41 
     42 typedef enum deFileFlag_e
     43 {
     44 	DE_FILE_NONBLOCKING		= (1<<0),	/*!< Set to non-blocking mode. Not supported on Win32!				*/
     45 	DE_FILE_CLOSE_ON_EXEC	= (1<<1)
     46 } deFileFlag;
     47 
     48 typedef enum deFileResult_e
     49 {
     50 	DE_FILERESULT_SUCCESS		= 0,
     51 	DE_FILERESULT_END_OF_FILE	= 1,
     52 	DE_FILERESULT_WOULD_BLOCK	= 2,
     53 	DE_FILERESULT_ERROR			= 3,
     54 
     55 	DE_FILERESULT_LAST
     56 } deFileResult;
     57 
     58 typedef enum deFilePosition_e
     59 {
     60 	DE_FILEPOSITION_BEGIN		= 0,
     61 	DE_FILEPOSITION_END			= 1,
     62 	DE_FILEPOSITION_CURRENT		= 2,
     63 
     64 	DE_FILEPOSITION_LAST
     65 } deFilePosition;
     66 
     67 /* File API. */
     68 
     69 deBool			deFileExists			(const char* filename);
     70 deBool			deDeleteFile			(const char* filename);
     71 
     72 deFile*			deFile_create			(const char* filename, deUint32 mode);
     73 deFile*			deFile_createFromHandle	(deUintptr handle);
     74 void			deFile_destroy			(deFile* file);
     75 
     76 deBool			deFile_setFlags			(deFile* file, deUint32 flags);
     77 
     78 deInt64			deFile_getPosition		(const deFile* file);
     79 deBool			deFile_seek				(deFile* file, deFilePosition base, deInt64 offset);
     80 deInt64			deFile_getSize			(const deFile* file);
     81 
     82 deFileResult	deFile_read				(deFile* file, void* buf, deInt64 bufSize, deInt64* numRead);
     83 deFileResult	deFile_write			(deFile* file, const void* buf, deInt64 bufSize, deInt64* numWritten);
     84 
     85 DE_END_EXTERN_C
     86 
     87 #endif /* _DEFILE_H */
     88