diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2022-08-07 02:18:06 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2022-08-07 02:18:06 +0000 |
commit | 4375fef1ade21bf37912ab23f8f36aaf1392b4ed (patch) | |
tree | 3374aaf9a6c76fd9cfb21233266dc9cf2067dae7 /src/VBox/Runtime | |
parent | 16572f899a5b4a48c813809d76b7bb76050df439 (diff) | |
download | VirtualBox-svn-4375fef1ade21bf37912ab23f8f36aaf1392b4ed.tar.gz |
IPRT/nocrt: Added clearerr, ferror, fgetc, fileno, fputc, fputs, fread, fseek, fseeko, ftell, ftello, fwrite, getc, puc, puts and setvbuf. bugref:10261
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@96091 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Runtime')
-rw-r--r-- | src/VBox/Runtime/Makefile.kmk | 16 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-clearerr.cpp | 43 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-ferror.cpp | 47 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fgetc.cpp | 51 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fileno.cpp | 51 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fputc.cpp | 51 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fputs.cpp | 53 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fread.cpp | 53 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fseek.cpp | 49 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fseeko.cpp | 49 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-ftell.cpp | 55 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-ftello.cpp | 50 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-fwrite.cpp | 53 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-getc.cpp | 51 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-putc.cpp | 51 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-puts.cpp | 58 | ||||
-rw-r--r-- | src/VBox/Runtime/r3/nocrt-setvbuf.cpp | 62 |
17 files changed, 843 insertions, 0 deletions
diff --git a/src/VBox/Runtime/Makefile.kmk b/src/VBox/Runtime/Makefile.kmk index f2951ac49ef..8ad8bada325 100644 --- a/src/VBox/Runtime/Makefile.kmk +++ b/src/VBox/Runtime/Makefile.kmk @@ -1832,8 +1832,24 @@ ifdef VBOX_WITH_NOCRT_STATIC r3/nocrt-fdopen.cpp \ r3/nocrt-tmpfile.cpp \ r3/nocrt-tmpfile_s.cpp \ + r3/nocrt-fileno.cpp \ r3/nocrt-fclose.cpp \ r3/nocrt-fflush.cpp \ + r3/nocrt-setvbuf.cpp \ + r3/nocrt-fseek.cpp \ + r3/nocrt-fseeko.cpp \ + r3/nocrt-ftell.cpp \ + r3/nocrt-ftello.cpp \ + r3/nocrt-fwrite.cpp \ + r3/nocrt-fputc.cpp \ + r3/nocrt-putc.cpp \ + r3/nocrt-fputs.cpp \ + r3/nocrt-puts.cpp \ + r3/nocrt-fread.cpp \ + r3/nocrt-fgetc.cpp \ + r3/nocrt-getc.cpp \ + r3/nocrt-clearerr.cpp \ + r3/nocrt-ferror.cpp \ RuntimeR3_SOURCES.x86 = $(RuntimeBaseR3_SOURCES.x86) \ common/math/cos.asm \ diff --git a/src/VBox/Runtime/r3/nocrt-clearerr.cpp b/src/VBox/Runtime/r3/nocrt-clearerr.cpp new file mode 100644 index 00000000000..4f69363ff73 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-clearerr.cpp @@ -0,0 +1,43 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - clearerr(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/stream.h> + + +#undef clearerr +void RT_NOCRT(clearerr)(FILE *pFile) +{ + RTStrmClearError(pFile); +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(clearerr); + diff --git a/src/VBox/Runtime/r3/nocrt-ferror.cpp b/src/VBox/Runtime/r3/nocrt-ferror.cpp new file mode 100644 index 00000000000..764ce72e852 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-ferror.cpp @@ -0,0 +1,47 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - ferror(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef ferror +int RT_NOCRT(ferror)(FILE *pFile) +{ + int rc = RTStrmError(pFile); + if (RT_SUCCESS(rc)) + return 0; + return 1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(ferror); + diff --git a/src/VBox/Runtime/r3/nocrt-fgetc.cpp b/src/VBox/Runtime/r3/nocrt-fgetc.cpp new file mode 100644 index 00000000000..a338b7672d2 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fgetc.cpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fgetc(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +/* Note! This is identical to the getc implemention. */ +#undef fgetc +int RT_NOCRT(fgetc)(FILE *pFile) +{ + unsigned char ch; + int rc = RTStrmReadEx(pFile, &ch, 1, NULL); + if (RT_SUCCESS(rc)) + return ch; + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fgetc); + diff --git a/src/VBox/Runtime/r3/nocrt-fileno.cpp b/src/VBox/Runtime/r3/nocrt-fileno.cpp new file mode 100644 index 00000000000..cdc926bf074 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fileno.cpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fileno(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/file.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fileno +int RT_NOCRT(fileno)(FILE *pFile) +{ + RTFILE hFile; + int rc = RTStrmQueryFileHandle(pFile, &hFile); + if (RT_SUCCESS(rc)) + return (int)RTFileToNative(hFile); + errno = EINVAL; + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fileno); + diff --git a/src/VBox/Runtime/r3/nocrt-fputc.cpp b/src/VBox/Runtime/r3/nocrt-fputc.cpp new file mode 100644 index 00000000000..22d2b5d8bc2 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fputc.cpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fputc(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +/* Note! This is identical to the putc implemention. */ +#undef fputc +int RT_NOCRT(fputc)(int iChar, FILE *pFile) +{ + unsigned char ch = (unsigned char)iChar; + int rc = RTStrmWriteEx(pFile, &ch, 1, NULL); + if (RT_SUCCESS(rc)) + return ch; + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fputc); + diff --git a/src/VBox/Runtime/r3/nocrt-fputs.cpp b/src/VBox/Runtime/r3/nocrt-fputs.cpp new file mode 100644 index 00000000000..37ec6f9da5b --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fputs.cpp @@ -0,0 +1,53 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fputs(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/nocrt/limits.h> +#include <iprt/nocrt/string.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fputs +int RT_NOCRT(fputs)(const char *psz, FILE *pFile) +{ + /* We're using RTStrmPutStr here for the benefit of console output optimization. */ + size_t cch = strlen(psz); + int rc = RTStrmPutStr(pFile, psz); + if (RT_SUCCESS(rc)) + return (int)RT_MIN(cch, (size_t)INT_MAX); + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fputs); + diff --git a/src/VBox/Runtime/r3/nocrt-fread.cpp b/src/VBox/Runtime/r3/nocrt-fread.cpp new file mode 100644 index 00000000000..85cbc9d2ed8 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fread.cpp @@ -0,0 +1,53 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fread(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/assert.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fread +size_t RT_NOCRT(fread)(void *pvBuf, size_t cbItem, size_t cItems, FILE *pFile) +{ + size_t cbToRead = cbItem * cItems; + AssertReturnStmt(cbToRead >= cbItem && cbItem >= cItems, errno = ERANGE, 0); + size_t cbRead = 0; + int rc = RTStrmReadEx(pFile, pvBuf, cbToRead, &cbRead); + if (RT_SUCCESS(rc)) + return cbRead; + errno = RTErrConvertToErrno(rc); + return 0; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fread); + diff --git a/src/VBox/Runtime/r3/nocrt-fseek.cpp b/src/VBox/Runtime/r3/nocrt-fseek.cpp new file mode 100644 index 00000000000..433e511b361 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fseek.cpp @@ -0,0 +1,49 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fseek(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fseek +int RT_NOCRT(fseek)(FILE *pFile, long off, int iMethod) +{ + int rc = RTStrmSeek(pFile, off, (uint32_t)iMethod); + if (RT_SUCCESS(rc)) + return 0; + errno = RTErrConvertToErrno(rc); + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fseek); + diff --git a/src/VBox/Runtime/r3/nocrt-fseeko.cpp b/src/VBox/Runtime/r3/nocrt-fseeko.cpp new file mode 100644 index 00000000000..365066d1718 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fseeko.cpp @@ -0,0 +1,49 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fseeko(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fseeko +int RT_NOCRT(fseeko)(FILE *pFile, off_t off, int iMethod) +{ + int rc = RTStrmSeek(pFile, off, (uint32_t)iMethod); + if (RT_SUCCESS(rc)) + return 0; + errno = RTErrConvertToErrno(rc); + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fseeko); + diff --git a/src/VBox/Runtime/r3/nocrt-ftell.cpp b/src/VBox/Runtime/r3/nocrt-ftell.cpp new file mode 100644 index 00000000000..bbbcfecf59e --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-ftell.cpp @@ -0,0 +1,55 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - ftell(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/nocrt/limits.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef ftell +long RT_NOCRT(ftell)(FILE *pFile) +{ + RTFOFF off = RTStrmTell(pFile); + if (off >= 0) + { + if (off < LONG_MAX) + return (long)off; + errno = EOVERFLOW; + } + else + errno = RTErrConvertToErrno((int)off); + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(ftell); + diff --git a/src/VBox/Runtime/r3/nocrt-ftello.cpp b/src/VBox/Runtime/r3/nocrt-ftello.cpp new file mode 100644 index 00000000000..91e571db2b4 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-ftello.cpp @@ -0,0 +1,50 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - ftello(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef ftello +off_t RT_NOCRT(ftello)(FILE *pFile) +{ + RTFOFF off = RTStrmTell(pFile); + AssertCompile(sizeof(off_t) == sizeof(off)); + if (off >= 0) + return off; + errno = RTErrConvertToErrno((int)off); + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(ftello); + diff --git a/src/VBox/Runtime/r3/nocrt-fwrite.cpp b/src/VBox/Runtime/r3/nocrt-fwrite.cpp new file mode 100644 index 00000000000..7b22893a8ae --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-fwrite.cpp @@ -0,0 +1,53 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - fwrite(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/assert.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef fwrite +size_t RT_NOCRT(fwrite)(void const *pvBuf, size_t cbItem, size_t cItems, FILE *pFile) +{ + size_t cbToWrite = cbItem * cItems; + AssertReturnStmt(cbToWrite >= cbItem && cbItem >= cItems, errno = ERANGE, 0); + size_t cbWritten = 0; + int rc = RTStrmWriteEx(pFile, pvBuf, cbToWrite, &cbWritten); + if (RT_SUCCESS(rc)) + return cbWritten; + errno = RTErrConvertToErrno(rc); + return 0; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(fwrite); + diff --git a/src/VBox/Runtime/r3/nocrt-getc.cpp b/src/VBox/Runtime/r3/nocrt-getc.cpp new file mode 100644 index 00000000000..bc620705709 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-getc.cpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - getc(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +/* Note! This is identical to the fgetc implemention. */ +#undef getc +int RT_NOCRT(getc)(FILE *pFile) +{ + unsigned char ch; + int rc = RTStrmReadEx(pFile, &ch, 1, NULL); + if (RT_SUCCESS(rc)) + return ch; + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(getc); + diff --git a/src/VBox/Runtime/r3/nocrt-putc.cpp b/src/VBox/Runtime/r3/nocrt-putc.cpp new file mode 100644 index 00000000000..5f1ff0420ab --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-putc.cpp @@ -0,0 +1,51 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - putc(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +/* Note! This is identical to the fputc implemention. */ +#undef putc +int RT_NOCRT(putc)(int iChar, FILE *pFile) +{ + unsigned char ch = (unsigned char)iChar; + int rc = RTStrmWriteEx(pFile, &ch, 1, NULL); + if (RT_SUCCESS(rc)) + return ch; + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(putc); + diff --git a/src/VBox/Runtime/r3/nocrt-puts.cpp b/src/VBox/Runtime/r3/nocrt-puts.cpp new file mode 100644 index 00000000000..ccb66771fd5 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-puts.cpp @@ -0,0 +1,58 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - puts(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/nocrt/string.h> +#include <iprt/nocrt/limits.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef puts +int RT_NOCRT(puts)(const char *psz) +{ + /* We're using RTStrmPutStr here for the benefit of console output optimization. */ + size_t cch = strlen(psz); + int rc = RTStrmPutStr(g_pStdOut, psz); + if (RT_SUCCESS(rc)) + { + /** @todo This isn't entirely perfect wrt multithreading. */ + rc = RTStrmPutStr(g_pStdOut, "\n"); + if (RT_SUCCESS(rc)) + return (int)RT_MIN(cch + 1, (size_t)INT_MAX); + } + errno = RTErrConvertToErrno(rc); + return RT_NOCRT_EOF; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(puts); + diff --git a/src/VBox/Runtime/r3/nocrt-setvbuf.cpp b/src/VBox/Runtime/r3/nocrt-setvbuf.cpp new file mode 100644 index 00000000000..1f6eefeb993 --- /dev/null +++ b/src/VBox/Runtime/r3/nocrt-setvbuf.cpp @@ -0,0 +1,62 @@ +/* $Id$ */ +/** @file + * IPRT - No-CRT - setvbuf(). + */ + +/* + * Copyright (C) 2022 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#define IPRT_NO_CRT_FOR_3RD_PARTY +#include "internal/nocrt.h" +#include <iprt/nocrt/stdio.h> +#include <iprt/nocrt/errno.h> +#include <iprt/assert.h> +#include <iprt/errcore.h> +#include <iprt/stream.h> + + +#undef setvbuf +int RT_NOCRT(setvbuf)(FILE *pFile, char *pchBuf, int iBufferingType, size_t cbBuf) +{ + Assert(!pchBuf); /* ignored */ + Assert(!cbBuf); /* ignored */ + + RTSTRMBUFMODE enmBufMode; + switch (iBufferingType) + { + case _IOFBF: enmBufMode = RTSTRMBUFMODE_FULL; break; + case _IOLBF: enmBufMode = RTSTRMBUFMODE_LINE; break; + case _IONBF: enmBufMode = RTSTRMBUFMODE_UNBUFFERED; break; + default: AssertFailedReturnStmt(errno = EINVAL, -1); + } + + int rc = RTStrmSetBufferingMode(pFile, enmBufMode); + if (RT_SUCCESS(rc)) + return 0; + errno = RTErrConvertToErrno(rc); + return -1; +} +RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(setvbuf); + |