
The idea behind Nuxi CloudABI is that it is targeted at (but not limited to) running networked services in a sandboxed environment. The model behind stdin, stdout and stderr is strongly focused on interactive tools in a command shell. CloudABI does not support the notion of stdin and stdout, as 'standard input/output' does not apply to services. The concept of stderr does makes sense though, as services do need some mechanism to log error messages in a uniform way. This patch extends libc++ in such a way that std::cin and std::cout and the associated <cstdio>/<cwchar> functions can be disabled through the flags _LIBCPP_HAS_NO_STDIN and _LIBCPP_HAS_NO_STDOUT, respectively. At the same time it attempts to clean up src/iostream.cpp a bit. Instead of using a single array of mbstate_t objects and hardcoding the array indices, it creates separate objects that declared next to the iostream objects and their buffers. The code is also restructured by interleaving the construction and setup of c* and wc* objects. That way it is more obvious that this is done identically. The c* and wc* objects already have separate unit tests. Make use of this fact by adding XFAILs in case libcpp-has-no-std* is set. That way the tests work in both directions. If stdin or stdout is disabled, these tests will therefore test for the absence of c* and wc*. Differential Revision: http://reviews.llvm.org/D8340 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233275 91177308-0d34-0410-b5e6-96231b3b80d8
149 lines
5.3 KiB
C++
149 lines
5.3 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// test <cstdio>
|
|
|
|
#include <cstdio>
|
|
#include <type_traits>
|
|
|
|
#ifndef BUFSIZ
|
|
#error BUFSIZ not defined
|
|
#endif
|
|
|
|
#ifndef EOF
|
|
#error EOF not defined
|
|
#endif
|
|
|
|
#ifndef FILENAME_MAX
|
|
#error FILENAME_MAX not defined
|
|
#endif
|
|
|
|
#ifndef FOPEN_MAX
|
|
#error FOPEN_MAX not defined
|
|
#endif
|
|
|
|
#ifndef L_tmpnam
|
|
#error L_tmpnam not defined
|
|
#endif
|
|
|
|
#ifndef NULL
|
|
#error NULL not defined
|
|
#endif
|
|
|
|
#ifndef SEEK_CUR
|
|
#error SEEK_CUR not defined
|
|
#endif
|
|
|
|
#ifndef SEEK_END
|
|
#error SEEK_END not defined
|
|
#endif
|
|
|
|
#ifndef SEEK_SET
|
|
#error SEEK_SET not defined
|
|
#endif
|
|
|
|
#ifndef TMP_MAX
|
|
#error TMP_MAX not defined
|
|
#endif
|
|
|
|
#ifndef _IOFBF
|
|
#error _IOFBF not defined
|
|
#endif
|
|
|
|
#ifndef _IOLBF
|
|
#error _IOLBF not defined
|
|
#endif
|
|
|
|
#ifndef _IONBF
|
|
#error _IONBF not defined
|
|
#endif
|
|
|
|
#ifndef stderr
|
|
#error stderr not defined
|
|
#endif
|
|
|
|
#ifndef stdin
|
|
#error stdin not defined
|
|
#endif
|
|
|
|
#ifndef stdout
|
|
#error stdout not defined
|
|
#endif
|
|
|
|
#include <cstdarg>
|
|
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wformat-zero-length"
|
|
|
|
int main()
|
|
{
|
|
std::FILE* fp = 0;
|
|
std::fpos_t fpos = {0};
|
|
std::size_t s = 0;
|
|
char* cp = 0;
|
|
std::va_list va;
|
|
static_assert((std::is_same<decltype(std::fclose(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fflush(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::setbuf(fp,cp)), void>::value), "");
|
|
static_assert((std::is_same<decltype(std::vfprintf(fp,"",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fprintf(fp," ")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fscanf(fp,"")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::snprintf(cp,0," ")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::sprintf(cp," ")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::sscanf("","")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vfprintf(fp,"",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vfscanf(fp,"",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vsnprintf(cp,0," ",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vsprintf(cp," ",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vsscanf("","",va)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fgetc(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fgets(cp,0,fp)), char*>::value), "");
|
|
static_assert((std::is_same<decltype(std::fputc(0,fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fputs("",fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::getc(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::putc(0,fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::ungetc(0,fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fread((void*)0,0,0,fp)), std::size_t>::value), "");
|
|
static_assert((std::is_same<decltype(std::fwrite((const void*)0,0,0,fp)), std::size_t>::value), "");
|
|
static_assert((std::is_same<decltype(std::fgetpos(fp, &fpos)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fseek(fp, 0,0)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::fsetpos(fp, &fpos)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::ftell(fp)), long>::value), "");
|
|
static_assert((std::is_same<decltype(std::rewind(fp)), void>::value), "");
|
|
static_assert((std::is_same<decltype(std::clearerr(fp)), void>::value), "");
|
|
static_assert((std::is_same<decltype(std::feof(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::ferror(fp)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::perror("")), void>::value), "");
|
|
|
|
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
|
|
static_assert((std::is_same<decltype(std::fopen("", "")), std::FILE*>::value), "");
|
|
static_assert((std::is_same<decltype(std::freopen("", "", fp)), std::FILE*>::value), "");
|
|
static_assert((std::is_same<decltype(std::remove("")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::rename("","")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::tmpfile()), std::FILE*>::value), "");
|
|
static_assert((std::is_same<decltype(std::tmpnam(cp)), char*>::value), "");
|
|
#endif
|
|
|
|
#ifndef _LIBCPP_HAS_NO_STDIN
|
|
static_assert((std::is_same<decltype(std::getchar()), int>::value), "");
|
|
#if _LIBCPP_STD_VER <= 11
|
|
static_assert((std::is_same<decltype(std::gets(cp)), char*>::value), "");
|
|
#endif
|
|
static_assert((std::is_same<decltype(std::scanf(" ")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vscanf("",va)), int>::value), "");
|
|
#endif
|
|
|
|
#ifndef _LIBCPP_HAS_NO_STDOUT
|
|
static_assert((std::is_same<decltype(std::printf(" ")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::putchar(0)), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::puts("")), int>::value), "");
|
|
static_assert((std::is_same<decltype(std::vprintf(" ",va)), int>::value), "");
|
|
#endif
|
|
}
|