1
0
Fork 0
forked from len0rd/rockbox

Remove FF_CREAT and FF_EXCL flags in from file code.

These flags aren't stored for an open file because they're simply
actions for open() to take, corresponding to O_CREAT and O_EXCL.
Just pass the oflag argument along to the deeper call, with some
minor filtering.

Change-Id: Ic8bcfba718ebf4228bdc45de3088af1974820557
This commit is contained in:
Michael Sevakis 2017-02-12 21:56:44 -05:00
parent dc22522c2c
commit 8ff1b6b603
2 changed files with 15 additions and 21 deletions

View file

@ -349,13 +349,14 @@ file_error:;
/* actually do the open gruntwork */ /* actually do the open gruntwork */
static int open_internal_inner2(const char *path, static int open_internal_inner2(const char *path,
struct filestr_desc *file, struct filestr_desc *file,
unsigned int callflags) unsigned int callflags,
int oflag)
{ {
int rc; int rc;
struct path_component_info compinfo; struct path_component_info compinfo;
if (callflags & FF_CREAT) if (oflag & O_CREAT)
callflags |= FF_PARENTINFO; callflags |= FF_PARENTINFO;
rc = open_stream_internal(path, callflags, &file->stream, &compinfo); rc = open_stream_internal(path, callflags, &file->stream, &compinfo);
@ -369,7 +370,7 @@ static int open_internal_inner2(const char *path,
if (rc > 0) if (rc > 0)
{ {
if (callflags & FF_EXCL) if (oflag & O_EXCL)
{ {
DEBUGF("File exists\n"); DEBUGF("File exists\n");
FILE_ERROR(EEXIST, -2); FILE_ERROR(EEXIST, -2);
@ -386,7 +387,7 @@ static int open_internal_inner2(const char *path,
compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */ compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */
} }
} }
else if (callflags & FF_CREAT) else if (oflag & O_CREAT)
{ {
if (compinfo.attr & ATTR_DIRECTORY) if (compinfo.attr & ATTR_DIRECTORY)
{ {
@ -483,15 +484,10 @@ static int open_internal_inner1(const char *path, int oflag,
/* O_CREAT and O_APPEND are fine without write mode /* O_CREAT and O_APPEND are fine without write mode
* for the former, an empty file is created but no data may be written * for the former, an empty file is created but no data may be written
* for the latter, no append will be allowed anyway */ * for the latter, no append will be allowed anyway */
if (oflag & O_CREAT) if (!(oflag & O_CREAT))
{ oflag &= ~O_EXCL; /* result is undefined: we choose "ignore" */
callflags |= FF_CREAT;
if (oflag & O_EXCL) rc = open_internal_inner2(path, file, callflags, oflag);
callflags |= FF_EXCL;
}
rc = open_internal_inner2(path, file, callflags);
if (rc < 0) if (rc < 0)
FILE_ERROR(ERRNO, rc * 10 - 3); FILE_ERROR(ERRNO, rc * 10 - 3);

View file

@ -130,15 +130,13 @@ enum fildes_and_obj_flags
FF_DIR = 0x00010000, /* expect dir; accept dir only */ FF_DIR = 0x00010000, /* expect dir; accept dir only */
FF_ANYTYPE = 0x00020000, /* succeed if either file or dir */ FF_ANYTYPE = 0x00020000, /* succeed if either file or dir */
FF_TYPEMASK = 0x00030000, /* mask of typeflags */ FF_TYPEMASK = 0x00030000, /* mask of typeflags */
FF_CREAT = 0x00040000, /* create if file doesn't exist */ FF_CHECKPREFIX = 0x00040000, /* detect if file is prefix of path */
FF_EXCL = 0x00080000, /* fail if creating and file exists */ FF_NOISO = 0x00080000, /* do not decode ISO filenames to UTF-8 */
FF_CHECKPREFIX = 0x00100000, /* detect if file is prefix of path */ FF_PROBE = 0x00100000, /* only test existence; don't open */
FF_NOISO = 0x00200000, /* do not decode ISO filenames to UTF-8 */ FF_CACHEONLY = 0x00200000, /* succeed only if in dircache */
FF_PROBE = 0x00400000, /* only test existence; don't open */ FF_INFO = 0x00400000, /* return info on self */
FF_CACHEONLY = 0x00800000, /* succeed only if in dircache */ FF_PARENTINFO = 0x00800000, /* return info on parent */
FF_INFO = 0x01000000, /* return info on self */ FF_MASK = 0x00ff0000,
FF_PARENTINFO = 0x02000000, /* return info on parent */
FF_MASK = 0x03ff0000,
}; };
/** Common data structures used throughout **/ /** Common data structures used throughout **/