2012-11-10 17:06:01 +01:00
|
|
|
/****************************************************************************
|
2023-08-24 05:43:57 +02:00
|
|
|
* libs/libc/stdio/lib_wrflush_unlocked.c
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-12-30 00:31:17 +01:00
|
|
|
#include "libc.h"
|
2012-11-10 17:06:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-08-24 05:43:57 +02:00
|
|
|
* Name: lib_wrflush_unlocked
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is simply a version of fflush that does not report an error if
|
|
|
|
* the file is not open for writing.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-24 05:43:57 +02:00
|
|
|
int lib_wrflush_unlocked(FAR FILE *stream)
|
2012-11-10 17:06:01 +01:00
|
|
|
{
|
2017-02-09 16:24:44 +01:00
|
|
|
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
2012-11-10 17:06:01 +01:00
|
|
|
/* Verify that we were passed a valid (i.e., non-NULL) stream */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2017-02-09 16:24:44 +01:00
|
|
|
if (stream == NULL)
|
2012-11-10 17:06:01 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-09 16:24:44 +01:00
|
|
|
/* Do nothing if there is no I/O buffer */
|
|
|
|
|
|
|
|
if (stream->fs_bufstart == NULL)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-11-10 17:06:01 +01:00
|
|
|
/* Verify that the stream is opened for writing... lib_fflush will
|
|
|
|
* return an error if it is called for a stream that is not opened for
|
|
|
|
* writing. Check that first so that this function will not fail in
|
|
|
|
* that case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((stream->fs_oflags & O_WROK) == 0)
|
|
|
|
{
|
|
|
|
/* Report that the success was successful if we attempt to flush a
|
|
|
|
* read-only stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush the stream. Return success if there is no buffered write data
|
|
|
|
* -- i.e., that the stream is opened for writing and that all of the
|
|
|
|
* buffered write data was successfully flushed by lib_fflush().
|
|
|
|
*/
|
|
|
|
|
2023-08-24 05:43:57 +02:00
|
|
|
return lib_fflush_unlocked(stream, true);
|
2017-02-09 16:24:44 +01:00
|
|
|
|
2012-11-10 17:06:01 +01:00
|
|
|
#else
|
|
|
|
/* Verify that we were passed a valid (i.e., non-NULL) stream */
|
|
|
|
|
2016-06-11 22:14:08 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
2012-11-10 17:06:01 +01:00
|
|
|
if (!stream)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
#endif
|
|
|
|
}
|