Fix bugs and make code tinier

- Fixed bug where stdio eof wasn't being sticky
- Fixed bug where fseeko() wasn't clearing eof state
- Removed assert() usage from libc favoring _unassert() / _npassert()
This commit is contained in:
Justine Tunney 2022-10-09 22:38:28 -07:00
parent 9b7c8db846
commit d5910e2673
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
115 changed files with 510 additions and 290 deletions

View file

@ -20,10 +20,10 @@
#include "libc/calls/struct/sigaction.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"
@ -39,6 +39,10 @@ char testlib_enable_tmp_setup_teardown;
TEST(fwrite, test) {
ASSERT_NE(NULL, (f = fopen(PATH, "wb")));
EXPECT_EQ(-1, fgetc(f));
ASSERT_FALSE(feof(f));
ASSERT_EQ(EBADF, errno);
ASSERT_EQ(EBADF, ferror(f));
clearerr(f);
EXPECT_EQ(5, fwrite("hello", 1, 5, f));
EXPECT_EQ(5, ftell(f));
EXPECT_NE(-1, fclose(f));
@ -60,6 +64,7 @@ TEST(fwrite, testSmallBuffer) {
ASSERT_NE(NULL, (f = fopen(PATH, "wb")));
setbuffer(f, gc(malloc(1)), 1);
EXPECT_EQ(-1, fgetc(f));
clearerr(f);
EXPECT_EQ(5, fwrite("hello", 1, 5, f));
EXPECT_EQ(5, ftell(f));
EXPECT_NE(-1, fclose(f));
@ -84,6 +89,7 @@ TEST(fwrite, testLineBuffer) {
ASSERT_NE(NULL, (f = fopen(PATH, "wb")));
setvbuf(f, NULL, _IOLBF, 64);
EXPECT_EQ(-1, fgetc(f));
clearerr(f);
EXPECT_EQ(5, fwrite("heyy\n", 1, 5, f));
EXPECT_EQ(0, fread(buf, 0, 0, f));
EXPECT_FALSE(feof(f));
@ -112,6 +118,7 @@ TEST(fwrite, testNoBuffer) {
ASSERT_NE(NULL, (f = fopen(PATH, "wb")));
setvbuf(f, NULL, _IONBF, 64);
EXPECT_EQ(-1, fgetc(f));
clearerr(f);
EXPECT_EQ(5, fwrite("heyy\n", 1, 5, f));
EXPECT_EQ(5, ftell(f));
EXPECT_NE(-1, fclose(f));