summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp')
-rw-r--r--src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp b/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp
new file mode 100644
index 0000000..525ba93
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/fgets/test3/test3.cpp
@@ -0,0 +1,73 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*============================================================================
+**
+** Source: test3.c
+**
+** Purpose: Tries to read from an empty file using fgets(), to verify
+** handling of EOF condition.
+**
+**
+**==========================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+ char inBuf[10];
+ const char filename[] = "testfile.tmp";
+
+ FILE * fp;
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /*write the empty file that we will use to test */
+ fp = fopen(filename, "w");
+ if (fp == NULL)
+ {
+ Fail("Unable to open file for write.\n");
+ }
+
+ /*Don't write anything*/
+
+ if (fclose(fp) != 0)
+ {
+ Fail("Error closing stream opened for write.\n");
+ }
+
+
+ /*Open the file and try to read.*/
+ fp = fopen(filename, "r");
+ if (fp == NULL)
+ {
+ Fail("Unable to open file for read.\n");
+ }
+
+
+ if (fgets(inBuf, sizeof(inBuf) , fp) != NULL)
+ {
+ /*NULL could also mean an error condition, but since the PAL
+ doesn't supply feof or ferror, we can't distinguish between
+ the two.*/
+ Fail("fgets doesn't handle EOF properly. When asked to read from "
+ "an empty file, it didn't return NULL as it should have.\n");
+ }
+
+ if (fclose(fp) != 0)
+ {
+ Fail("Error closing an empty file after trying to use fgets().\n");
+ }
+ PAL_Terminate();
+ return PASS;
+
+}
+
+
+
+
+