fixed a bug of ase_fio_open in handling flags
This commit is contained in:
		| @ -15,10 +15,11 @@ enum ase_fio_open_flag_t | ||||
|  | ||||
| 	ASE_FIO_READ      = (1 << 1), | ||||
| 	ASE_FIO_WRITE     = (1 << 2), | ||||
| 	ASE_FIO_CREATE    = (1 << 3), | ||||
| 	ASE_FIO_TRUNCATE  = (1 << 4), | ||||
| 	ASE_FIO_EXCLUSIVE = (1 << 5), | ||||
| 	ASE_FIO_APPEND    = (1 << 6), | ||||
| 	ASE_FIO_APPEND    = (1 << 3), | ||||
|  | ||||
| 	ASE_FIO_CREATE    = (1 << 4), | ||||
| 	ASE_FIO_TRUNCATE  = (1 << 5), | ||||
| 	ASE_FIO_EXCLUSIVE = (1 << 6), | ||||
| 	ASE_FIO_SYNC      = (1 << 7), | ||||
|  | ||||
| 	/* for ms windows only */ | ||||
| @ -60,6 +61,14 @@ struct ase_fio_t | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| /****f* ase.fio/ase_fio_open | ||||
|  * NAME | ||||
|  *  ase_fio_open - open a file | ||||
|  * | ||||
|  * PARAMETERS | ||||
|  *  | ||||
|  * SYNOPSIS | ||||
|  */ | ||||
| ase_fio_t* ase_fio_open ( | ||||
| 	ase_mmgr_t* mmgr, | ||||
| 	ase_size_t ext, | ||||
| @ -67,6 +76,7 @@ ase_fio_t* ase_fio_open ( | ||||
| 	int flags, | ||||
| 	int mode | ||||
| ); | ||||
| /******/ | ||||
|  | ||||
| void ase_fio_close ( | ||||
| 	ase_fio_t* fio | ||||
|  | ||||
| @ -16,10 +16,11 @@ enum ase_sio_open_flag_t | ||||
|  | ||||
|         ASE_SIO_READ      = ASE_FIO_READ, | ||||
|         ASE_SIO_WRITE     = ASE_FIO_WRITE, | ||||
| 	ASE_SIO_APPEND    = ASE_FIO_APPEND, | ||||
|  | ||||
| 	ASE_SIO_CREATE    = ASE_FIO_CREATE, | ||||
|         ASE_SIO_TRUNCATE  = ASE_FIO_TRUNCATE, | ||||
| 	ASE_SIO_EXCLUSIVE = ASE_FIO_EXCLUSIVE, | ||||
| 	ASE_SIO_APPEND    = ASE_FIO_APPEND, | ||||
| 	ASE_SIO_SYNC      = ASE_FIO_SYNC, | ||||
|  | ||||
|         ASE_SIO_NOSHRD    = ASE_FIO_NOSHRD, | ||||
|  | ||||
| @ -73,14 +73,19 @@ ase_fio_t* ase_fio_init ( | ||||
| 		DWORD creation_disposition = 0; | ||||
| 		DWORD attributes = FILE_ATTRIBUTE_NORMAL; | ||||
|  | ||||
| 		if (flags & ASE_FIO_READ) desired_access |= GENERIC_READ; | ||||
| 		if (flags & ASE_FIO_WRITE) desired_access |= GENERIC_WRITE; | ||||
| 		if (flags & ASE_FIO_APPEND)   | ||||
| 		{ | ||||
| 			/* this is not officialy documented for CreateFile. | ||||
| 			 * ZwCreateFile (kernel) seems to document it */ | ||||
| 			desired_access |= FILE_APPEND_DATA; | ||||
| 		} | ||||
| 		else if (flags & ASE_FIO_WRITE) | ||||
| 		{ | ||||
| 			/* In WIN32, FILE_APPEND_DATA and GENERIC_WRITE can't | ||||
| 			 * be used together */ | ||||
| 			desired_access |= GENERIC_WRITE; | ||||
| 		} | ||||
| 		if (flags & ASE_FIO_READ) desired_access |= GENERIC_READ; | ||||
| 	 | ||||
| 		if (flags & ASE_FIO_CREATE)  | ||||
| 		{ | ||||
| @ -132,13 +137,24 @@ ase_fio_t* ase_fio_init ( | ||||
| 		if (ase_wcstombs_strict (path,  | ||||
| 			path_mb, ASE_COUNTOF(path_mb)) == -1) return ASE_NULL; | ||||
| 	#endif | ||||
|  | ||||
| 		/* | ||||
| 		 * rwa -> RDWR   | APPEND | ||||
| 		 * ra  -> RDONLY | APPEND | ||||
| 		 * wa  -> WRONLY | APPEND | ||||
| 		 * a   -> WRONLY | APPEND | ||||
| 		 */ | ||||
| 		if ((flags & ASE_FIO_READ) &&  | ||||
| 		    (flags & ASE_FIO_WRITE)) desired_access |= O_RDWR; | ||||
| 		else if (flags & ASE_FIO_READ) desired_access |= O_RDONLY; | ||||
| 		else desired_access |= O_WRONLY; | ||||
| 		else if (flags & ASE_FIO_WRITE) desired_access |= O_WRONLY; | ||||
|  | ||||
| 		if (flags & ASE_FIO_APPEND)  | ||||
| 		{ | ||||
| 			if (!(flags & ASE_FIO_READ) && | ||||
| 			    !(flags & ASE_FIO_WRITE)) desired_access |= O_WRONLY; | ||||
| 			desired_access |= O_APPEND; | ||||
| 		} | ||||
|  | ||||
| 		if (flags & ASE_FIO_APPEND) desired_access |= O_APPEND; | ||||
| 		if (flags & ASE_FIO_CREATE) desired_access |= O_CREAT; | ||||
| 		if (flags & ASE_FIO_TRUNCATE) desired_access |= O_TRUNC; | ||||
| 		if (flags & ASE_FIO_EXCLUSIVE) desired_access |= O_EXCL; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user