Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/libc_init_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ reent_init(struct _clib4 *__clib4, BOOL fallback) {
if (!__clib4->_iob_pool) {
goto out;
}
DebugPrintF("Allocated file IO pool. _iob_pool : 0x%lx\n", __clib4->_iob_pool);

SHOWMSG("Allocating wide_status");
/* Initialize wchar stuff */
Expand Down Expand Up @@ -284,6 +285,7 @@ reent_exit(struct _clib4 *__clib4, BOOL fallback) {
/* Free IO memory pool */
if (__clib4->_iob_pool != NULL) {
SHOWMSG("Freeing _iob_pool and all unfreed memory");
DebugPrintF("Freeing _iob_pool and all unfreed memory. _iob_pool : 0x%lx\n", __clib4->_iob_pool);
FreeSysObject(ASOT_MEMPOOL, __clib4->_iob_pool);
}

Expand Down
1 change: 1 addition & 0 deletions library/stdio/fclose.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fclose(FILE *stream) {
/* Get rid of any custom file buffer allocated. */
if (file->iob_CustomBuffer != NULL) {
SHOWMSG("Delete allocated buffer");
DebugPrintF("Freeing pooled buffer: 0x%lx\n", file->iob_CustomBuffer);
FreeVecPooled(__clib4->_iob_pool, file->iob_CustomBuffer);
file->iob_CustomBuffer = NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions library/stdio/file_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ FILE_CONSTRUCTOR(stdio_file_init) {
if (buffer == NULL)
goto out;

DebugPrintF("Allocating stdio buffer: %ld\n", BUFSIZ + (__clib4->__cache_line_size - 1));

ClearMem(buffer, BUFSIZ + (__clib4->__cache_line_size - 1));

/* Allocate memory for an arbitration mechanism, then initialize it. */
Expand Down
2 changes: 2 additions & 0 deletions library/stdio/openiob.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ __open_iob(struct _clib4 *__clib4, const char *filename, const char *mode, int f
goto out;
}

DebugPrintF("Allocated file io buffer: %ld\n", BUFSIZ + (__clib4->__cache_line_size - 1));

ClearMem(buffer, BUFSIZ + (__clib4->__cache_line_size - 1));

if (file_descriptor < 0) {
Expand Down
1 change: 1 addition & 0 deletions library/stdio/setvbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ setvbuf(FILE *stream, char *buf, int bufmode, size_t size) {
__set_errno_r(__clib4, ENOBUFS);
goto out;
}
DebugPrintF("Allocated vbuf: %ld\n", size + (__clib4->__cache_line_size - 1));
}
}

Expand Down
1 change: 0 additions & 1 deletion library/wmem/wmem_allocator_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ wmem_block_alloc(void *private_data, const size_t size, int32_t alignment) {
/* and return the data pointer */
return data; //WMEM_CHUNK_TO_DATA(chunk);
}
#endif

static void
wmem_block_free(void *private_data, void *ptr) {
Expand Down
21 changes: 21 additions & 0 deletions test_programs/io/amigados_read_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define __USE_INLINE__
#include <proto/dos.h>
#include <proto/exec.h>
#include <dos/dos.h>

int main() {
BPTR file = Open("test.c", MODE_OLDFILE);
if (!file) return RETURN_FAIL;

char buffer[1024];
LONG bytesRead;

while ((bytesRead = Read(file, buffer, sizeof(buffer))) > 0) {
Write(Output(), buffer, bytesRead);
}
FPuts(Output(), "\n"); // force output
FFlush(Output());

Close(file);
return RETURN_OK;
}
18 changes: 18 additions & 0 deletions test_programs/io/cstd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>

int main() {
FILE *f = fopen("test.c", "r");
int ch;

if (!f) {
perror("fopen");
return 1;
}

while ((ch = fgetc(f)) != EOF) {
putchar(ch);
}

fclose(f);
return 0;
}
14 changes: 14 additions & 0 deletions test_programs/io/line-by-line.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <fstream>
#include <string>

int main() {
std::ifstream file("test.c");
std::string line;

while (std::getline(file, line)) {
std::cout << line << '\n';
}

return 0;
}
15 changes: 15 additions & 0 deletions test_programs/io/posix_read_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <fcntl.h>
#include <unistd.h>

int main() {
int fd = open("test.c", O_RDONLY);
char buffer[1024];
ssize_t bytes;

while ((bytes = read(fd, buffer, sizeof(buffer))) > 0) {
write(STDOUT_FILENO, buffer, bytes);
}

close(fd);
return 0;
}
19 changes: 19 additions & 0 deletions test_programs/io/streambuf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <fstream>

int main() {
std::ifstream file("test.c");

if (!file.is_open()) {
std::cerr << "Failed to open file.\n";
return 1;
}

// Get the stream buffer from the file
std::streambuf* pbuf = file.rdbuf();

// Write the contents of the file directly to std::cout
std::cout << pbuf;

return 0;
}
Loading