summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 028bdbe9f0..cb918c6eab 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -349,13 +349,14 @@ file_error:;
349/* actually do the open gruntwork */ 349/* actually do the open gruntwork */
350static int open_internal_inner2(const char *path, 350static int open_internal_inner2(const char *path,
351 struct filestr_desc *file, 351 struct filestr_desc *file,
352 unsigned int callflags) 352 unsigned int callflags,
353 int oflag)
353{ 354{
354 int rc; 355 int rc;
355 356
356 struct path_component_info compinfo; 357 struct path_component_info compinfo;
357 358
358 if (callflags & FF_CREAT) 359 if (oflag & O_CREAT)
359 callflags |= FF_PARENTINFO; 360 callflags |= FF_PARENTINFO;
360 361
361 rc = open_stream_internal(path, callflags, &file->stream, &compinfo); 362 rc = open_stream_internal(path, callflags, &file->stream, &compinfo);
@@ -369,7 +370,7 @@ static int open_internal_inner2(const char *path,
369 370
370 if (rc > 0) 371 if (rc > 0)
371 { 372 {
372 if (callflags & FF_EXCL) 373 if (oflag & O_EXCL)
373 { 374 {
374 DEBUGF("File exists\n"); 375 DEBUGF("File exists\n");
375 FILE_ERROR(EEXIST, -2); 376 FILE_ERROR(EEXIST, -2);
@@ -386,7 +387,7 @@ static int open_internal_inner2(const char *path,
386 compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */ 387 compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */
387 } 388 }
388 } 389 }
389 else if (callflags & FF_CREAT) 390 else if (oflag & O_CREAT)
390 { 391 {
391 if (compinfo.attr & ATTR_DIRECTORY) 392 if (compinfo.attr & ATTR_DIRECTORY)
392 { 393 {
@@ -483,15 +484,10 @@ static int open_internal_inner1(const char *path, int oflag,
483 /* O_CREAT and O_APPEND are fine without write mode 484 /* O_CREAT and O_APPEND are fine without write mode
484 * for the former, an empty file is created but no data may be written 485 * for the former, an empty file is created but no data may be written
485 * for the latter, no append will be allowed anyway */ 486 * for the latter, no append will be allowed anyway */
486 if (oflag & O_CREAT) 487 if (!(oflag & O_CREAT))
487 { 488 oflag &= ~O_EXCL; /* result is undefined: we choose "ignore" */
488 callflags |= FF_CREAT;
489
490 if (oflag & O_EXCL)
491 callflags |= FF_EXCL;
492 }
493 489
494 rc = open_internal_inner2(path, file, callflags); 490 rc = open_internal_inner2(path, file, callflags, oflag);
495 if (rc < 0) 491 if (rc < 0)
496 FILE_ERROR(ERRNO, rc * 10 - 3); 492 FILE_ERROR(ERRNO, rc * 10 - 3);
497 493