2017-02-09 17:58:51 +01:00
|
|
|
/****************************************************************************
|
2021-06-10 07:51:27 +02:00
|
|
|
* apps/testing/ostest/setvbuf.c
|
2017-02-09 17:58:51 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02: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
|
2017-02-09 17:58:51 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-02-09 17:58:51 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02: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.
|
2017-02-09 17:58:51 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* setvbuf_test
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int setvbuf_test(void)
|
|
|
|
{
|
|
|
|
FILE *stream;
|
|
|
|
char buffer[64];
|
|
|
|
int ret;
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("setvbuf_test: Test NO buffering\n");
|
|
|
|
|
2017-02-09 17:58:51 +01:00
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
2019-02-26 01:14:59 +01:00
|
|
|
return ERROR;
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = setvbuf(stream, NULL, _IONBF, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("setvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, NULL, _IONBF, 0) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream, "setvbuf_test: Using NO buffering\r\n");
|
|
|
|
|
|
|
|
/* Close the stream. setvbuf() may only be called AFTER the stream has
|
|
|
|
* been opened and BEFORE any operations have been performed on the
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
printf("setvbuf_test: Test default FULL buffering\n");
|
|
|
|
|
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
2017-02-09 17:58:51 +01:00
|
|
|
|
|
|
|
ret = setvbuf(stream, NULL, _IOFBF, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("ssetvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, NULL, _IOFBF, 0) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream, "setvbuf_test: Using default FULL buffering\r\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
/* Close the stream. setvbuf() may only be called AFTER the stream has
|
|
|
|
* been opened and BEFORE any operations have been performed on the
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
printf("setvbuf_test: Test FULL buffering, buffer size 64\n");
|
|
|
|
|
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
2017-02-09 17:58:51 +01:00
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
|
|
|
return ERROR;
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
ret = setvbuf(stream, NULL, _IOFBF, 64);
|
2017-02-09 17:58:51 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("ssetvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, NULL, _IOFBF, 64) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream, "setvbuf_test: Using FULL buffering, buffer size 64\r\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
/* Close the stream. setvbuf() may only be called AFTER the stream has
|
|
|
|
* been opened and BEFORE any operations have been performed on the
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
printf("setvbuf_test: Test FULL buffering, pre-allocated buffer\n");
|
|
|
|
|
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = setvbuf(stream, buffer, _IOFBF, 64);
|
2017-02-09 17:58:51 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("ssetvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, buffer, _IOFBF, 64) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream,
|
|
|
|
"setvbuf_test: Using FULL buffering, pre-allocated buffer\r\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
/* Close the stream. setvbuf() may only be called AFTER the stream has
|
|
|
|
* been opened and BEFORE any operations have been performed on the
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
printf("setvbuf_test: Test LINE buffering, buffer size 64\n");
|
|
|
|
|
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = setvbuf(stream, NULL, _IOLBF, 64);
|
2017-02-09 17:58:51 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("setvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, NULL, _IOLBF, 64) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream, "setvbuf_test: Using LINE buffering, buffer size 64\r\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
/* Close the stream. setvbuf() may only be called AFTER the stream has
|
|
|
|
* been opened and BEFORE any operations have been performed on the
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
printf("setvbuf_test: Test FULL buffering, pre-allocated buffer\n");
|
|
|
|
|
|
|
|
stream = fopen("/dev/console", "w");
|
|
|
|
if (stream == NULL)
|
|
|
|
{
|
|
|
|
printf("setvbuf_test ERROR: fopen(dev/console, rw) failed\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = setvbuf(stream, buffer, _IOLBF, 64);
|
2017-02-09 17:58:51 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-02-26 01:14:59 +01:00
|
|
|
printf("setvbuf_test ERROR: "
|
|
|
|
"setvbuf(stream, buffer, _IOLBF, 64) failed\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:14:59 +01:00
|
|
|
fprintf(stream,
|
|
|
|
"setvbuf_test: Using FULL buffering, pre-allocated buffer\r\n");
|
2017-02-09 17:58:51 +01:00
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_STDIO_DISABLE_BUFFERING */
|