mirror of
https://github.com/deadw00d/AROS.git
synced 2025-12-06 21:40:57 +00:00
Changes:
- ported fgetwc - ported fgetws - Created a test unit for wprintf
This commit is contained in:
@ -1103,10 +1103,10 @@ int utime(const char *filename, const struct utimbuf *buf)
|
||||
#void setutxent(void)
|
||||
#
|
||||
# * wchar.h: Reserve LVOs, we may want to provide own implementation
|
||||
.skip 3
|
||||
.skip 1
|
||||
#wint_t btowc(int)
|
||||
#wint_t fgetwc(FILE * stream)
|
||||
#wchar_t *fgetws(wchar_t *restrict, int, FILE *restrict stream)
|
||||
wint_t fgetwc(FILE * stream)
|
||||
wchar_t *fgetws(wchar_t * restrict s, int n, FILE * restrict stream)
|
||||
wint_t fputwc(wchar_t wc, FILE * fp)
|
||||
.alias putwc
|
||||
.skip 2
|
||||
|
||||
@ -567,6 +567,8 @@ CRT := \
|
||||
posixc/fgetpos \
|
||||
posixc/fgetpos64 \
|
||||
posixc/fgets \
|
||||
posixc/fgetwc \
|
||||
posixc/fgetws \
|
||||
posixc/fileno \
|
||||
posixc/flock \
|
||||
posixc/flockfile \
|
||||
|
||||
47
compiler/crt/posixc/fgetwc.c
Normal file
47
compiler/crt/posixc/fgetwc.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (C) 1995-2022, The AROS Development Team. All rights reserved.
|
||||
|
||||
C99 function fgetwc().
|
||||
Original source from libnix
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
NAME */
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
|
||||
wint_t fgetwc(
|
||||
|
||||
/* SYNOPSIS */
|
||||
FILE *stream)
|
||||
|
||||
/* FUNCTION
|
||||
Read one wide character from the stream. If there is no character
|
||||
available or an error occurred, the function returns WEOF.
|
||||
|
||||
INPUTS
|
||||
stream - Read from this stream
|
||||
|
||||
RESULT
|
||||
The wide character read or WEOF on end of file or error.
|
||||
|
||||
NOTES
|
||||
|
||||
EXAMPLE
|
||||
|
||||
BUGS
|
||||
|
||||
SEE ALSO
|
||||
|
||||
INTERNALS
|
||||
|
||||
******************************************************************************/
|
||||
{
|
||||
wint_t b;
|
||||
if (fread((char *) &b, 1, sizeof(wint_t), stream))
|
||||
return b;
|
||||
return -1;
|
||||
}
|
||||
75
compiler/crt/posixc/fgetws.c
Normal file
75
compiler/crt/posixc/fgetws.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (C) 1995-2022, The AROS Development Team. All rights reserved.
|
||||
|
||||
C99 function fgetws().
|
||||
Original source from libnix
|
||||
*/
|
||||
|
||||
/*****************************************************************************
|
||||
|
||||
NAME */
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *fgetws(
|
||||
|
||||
/* SYNOPSIS */
|
||||
wchar_t * restrict s,
|
||||
int n,
|
||||
FILE * restrict stream)
|
||||
|
||||
/* FUNCTION
|
||||
Read one line of wide characters from the stream into the buffer.
|
||||
Reading will stop, when a newline ('\n') is encountered, WEOF
|
||||
or when the buffer is full. If a newline is read, then it is
|
||||
put into the buffer. The last wide character in the buffer is always
|
||||
'\0' (Therefore at most size-1 characters can be read in one go).
|
||||
|
||||
INPUTS
|
||||
s - Write wide characters into this buffer
|
||||
n - This is the size of the buffer in wide characters.
|
||||
stream - Read from this stream
|
||||
|
||||
RESULT
|
||||
buffer or NULL in case of an error or EOF.
|
||||
|
||||
NOTES
|
||||
|
||||
EXAMPLE
|
||||
// Read a file line by line
|
||||
wchar_t line[256];
|
||||
|
||||
// Read until WEOF
|
||||
while (fgetws (line, sizeof (line), fh))
|
||||
{
|
||||
// Evaluate the line
|
||||
}
|
||||
|
||||
BUGS
|
||||
|
||||
SEE ALSO
|
||||
|
||||
INTERNALS
|
||||
|
||||
******************************************************************************/
|
||||
{
|
||||
wchar_t *s2 = s;
|
||||
|
||||
flockfile(stream);
|
||||
while (--n) {
|
||||
int c = fgetwc(stream);
|
||||
if (c == WEOF) {
|
||||
if (s2 == s) {
|
||||
funlockfile(stream);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
*s2++ = c;
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
*s2++ = '\0';
|
||||
funlockfile(stream);
|
||||
return s;
|
||||
}
|
||||
@ -126,9 +126,9 @@ int vfwprintf(struct __sFILE * restrict stream,
|
||||
const wchar_t * restrict format, va_list arg); */
|
||||
|
||||
/* Wide-character input/output functions. */
|
||||
/* NOTIMPL wint_t fgetwc(struct __sFILE *stream); */
|
||||
/* NOTIMPL wchar_t *fgetws(wchar_t * restrict s,
|
||||
int n, struct __sFILE * restrict stream); */
|
||||
wint_t fgetwc(struct __sFILE *stream);
|
||||
wchar_t *fgetws(wchar_t * restrict s,
|
||||
int n, struct __sFILE * restrict stream);
|
||||
wint_t fputwc(wchar_t wc, struct __sFILE *fp);
|
||||
/* NOTIMPL int fputws(const wchar_t * restrict s,
|
||||
struct __sFILE * restrict stream); */
|
||||
|
||||
55
developer/debug/test/crt/stdc/cunit-crt-wprintf.c
Normal file
55
developer/debug/test/crt/stdc/cunit-crt-wprintf.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright <20> 2025, The AROS Development Team. All rights reserved.
|
||||
$Id$
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include <CUnit/CUnitCI.h>
|
||||
|
||||
/* Test printing an ASCII wide string with wprintf */
|
||||
static void test_wprintf_1(void) {
|
||||
|
||||
FILE * temp_file = tmpfile();
|
||||
|
||||
// Redirect stdout to temp_file to capture output
|
||||
int original_stdout_fd = dup(fileno(stdout));
|
||||
int tmp_fd = fileno(temp_file);
|
||||
if (dup2(tmp_fd, fileno(stdout)) == -1) {
|
||||
fclose(temp_file);
|
||||
}
|
||||
|
||||
// Test wide character string printing
|
||||
const wchar_t* test_string = L"Hello, World!";
|
||||
int result = wprintf(L"Test: %ls\n", test_string);
|
||||
|
||||
// Restore stdout
|
||||
if (dup2(original_stdout_fd, fileno(stdout)) == -1) {
|
||||
fclose(temp_file);
|
||||
}
|
||||
|
||||
// Check if print was successful
|
||||
CU_ASSERT(result > 0);
|
||||
|
||||
// Rewind the temp file to read its contents
|
||||
rewind(temp_file);
|
||||
|
||||
// Buffer to read the output
|
||||
wchar_t buffer[100];
|
||||
fgetws(buffer, sizeof(buffer), temp_file);
|
||||
|
||||
// Verify the output
|
||||
CU_ASSERT(wcscmp(buffer, L"Test: Hello, World!\n") == 0);
|
||||
|
||||
// Close the temporary file
|
||||
fclose(temp_file);
|
||||
}
|
||||
|
||||
// Main function to run the tests
|
||||
int main(int argc, char** argv) {
|
||||
//Define test suite
|
||||
CU_CI_DEFINE_SUITE("wprintf_Suite", NULL, NULL, NULL, NULL);
|
||||
CUNIT_CI_TEST(test_wprintf_1);
|
||||
|
||||
return CU_CI_RUN_SUITES();
|
||||
}
|
||||
|
||||
@ -68,7 +68,8 @@ CUNITSTDCTESTFILES := \
|
||||
cunit-crt-wcrtomb \
|
||||
cunit-crt-wcsnrtombs \
|
||||
cunit-crt-wcsrtombs \
|
||||
cunit-crt-wcsncmp
|
||||
cunit-crt-wcsncmp \
|
||||
cunit-crt-wprintf
|
||||
|
||||
#MM- test-crt : test-crt-stdc test-crt-stdc-$(AROS_TARGET_CPU)
|
||||
#MM- test-crt-quick : test-crt-stdc-quick test-crt-stdc-$(AROS_TARGET_CPU)-quick
|
||||
|
||||
@ -77,6 +77,7 @@ If NOT WARN
|
||||
Execute S/Test cunit/crt/stdc/cunit-crt-mbrlen ;mbrlen_Suite
|
||||
Execute S/Test cunit/crt/stdc/cunit-crt-mbsnrtowcs ;mbsnrtowcs_Suite
|
||||
Execute S/Test cunit/crt/stdc/cunit-crt-mbsrtowcs ;mbsrtowcs_Suite
|
||||
Execute S/Test cunit/crt/stdc/cunit-crt-wprintf ;wprintf_Suite
|
||||
Execute S/Test cunit/crt/posix/cunit-crt-fread ;fread_Suite
|
||||
Copy SYS:Development/Debug/Tests/crt/posix/execl2_slave SYS:
|
||||
Execute S/Test cunit/crt/posix/cunit-crt-vfork ;vfork_Suite
|
||||
@ -110,7 +111,7 @@ If NOT WARN
|
||||
Execute S/Test cunit/cplusplus/cunit-cplusplus-static ;CPlusPlus_Static_Suite
|
||||
|
||||
Echo "===================" >DEBUG:
|
||||
Echo "Expected tests: 321" >DEBUG:
|
||||
Echo "Expected tests: 322" >DEBUG:
|
||||
Echo "===================" >DEBUG:
|
||||
Endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user