~aleteoryx/muditaos

ref: d4277039d3dbab089ad880129f89f8bce03d95d2 muditaos/module-vfs/freertos-fat-custom/src/ff_stdio_flush.c -rw-r--r-- 1.2 KiB
d4277039 — Lucjan Bryndza [EGD-4179] Recursive file list API (#912) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "portable.h"

/* FreeRTOS+FAT includes. */
#include "ff_headers.h"
#include "ff_stdio.h"

#if (ffconfigTIME_SUPPORT != 0)
#include <time.h>
#endif

#include "ff_file_flush.h"

int prvFFErrorToErrno(FF_Error_t xError);

int ff_fflush(FF_FILE *pxStream)
{
    FF_Error_t xError;
    int iReturn, ff_errno;

#if (ffconfigDEV_SUPPORT != 0)
    {
        /* Currently device support is in an experimental state.  It will allow
            to create virtual files. The I/O data to those files will be redirected
            to their connected "drivers". */
        if (pxStream != NULL) {
            FF_Device_Flush(pxStream);
        }
    }
#endif

    xError   = FF_Flush(pxStream);
    ff_errno = prvFFErrorToErrno(xError);

    if (ff_errno == 0) {
        iReturn = 0;
    }
    else {
        /* Return -1 for error as per normal fclose() semantics. */
        iReturn = -1;
    }

    /* Store the errno to thread local storage. */
    stdioSET_ERRNO(ff_errno);

    return iReturn;
}