Commit Graph

24 Commits

Author SHA1 Message Date
Stephen Heumann
e9de42d6c4 fopen: do not require read access when opening a file for append only.
This can cause an error if the file's permissions deny read access.
2020-02-17 19:49:18 -06:00
Stephen Heumann
e5360c9605 Spellcheck comments. 2020-02-16 13:29:53 -06:00
Stephen Heumann
573bc6efa9 Use consistent indentation within files.
Tabs have been expanded to spaces in several files that use mainly spaces for indentation.

The files ctype.asm, stdio.asm, and string.asm consistently use tabs for indentation. The tabs in these files have been left alone, except that a few tabs between sentences in comments were changed to spaces.  One space-indented line in stdio.asm was changed to use a tab.
2020-02-16 13:28:18 -06:00
Stephen Heumann
9af1c093cb Ensure tmpfile() doesn't access a file created by someone else.
This could happen due to a race condition, which shouldn't generally be an issue on the GS but is at least theoretically possible under GNO or Golden Gate.
2020-01-31 12:47:34 -06:00
Stephen Heumann
c439f2e3ea Make tmpnam() return the pointer passed to it, if non-null.
This is what the standards call for. It was previously always returning a pointer to its internal buffer.
2020-01-31 12:45:02 -06:00
Stephen Heumann
27a32d82bd Allow 'b' to come before '+' in freopen modes (e.g. "wb+").
Previously, only forms like "w+b" worked.
2020-01-30 21:16:48 -06:00
Stephen Heumann
c77c5927d9 Support "x" in fopen()/freopen() mode strings (C11).
If the mode string ends in "x", opening a file for writing will fail if the file already exists.
2020-01-30 20:15:45 -06:00
Stephen Heumann
bd6d517854 Note that ~RemoveWord is used by scanf, not printf. 2020-01-30 18:51:59 -06:00
Stephen Heumann
07011e5b05 Fix issue causing potential stack corruption in scanf().
This could happen if a scan error occurred and certain conversion specifiers containing the % character in a scanset (e.g. %4[%]) appeared as subsequent elements in the format string. The fix is to more thoroughly parse the format string when cleaning up after a scan error.

This fixes #26.
2020-01-22 07:40:40 -06:00
Stephen Heumann
24ec2ae9bc Fix perror() issues.
perror() should write only a single new-line. Also, it should not write the prefix string, colon and space if the prefix string pointer is NULL or if it points to an empty string.
2018-09-09 21:43:14 -05:00
Stephen Heumann
2be73c4e5d Make strerror() return a valid error string for unknown errno values.
This is required by C99 and later.
2018-09-09 21:26:21 -05:00
Stephen Heumann
2d20af84fd Fix support for 'h' length modifier in scanf.
This got broken when adding support for 'hh'.
2018-09-09 20:55:23 -05:00
Stephen Heumann
a11660f597 Implement support for 'hh' length modifier in *scanf.
Also support '%ln', although the length that can be reported is still limited to 64k.
2018-03-22 22:10:56 -05:00
Stephen Heumann
5ee6e87f44 Implement support for 'hh' length modifier in *printf.
This corresponds to signed char or unsigned char (although arguments of those types will have been promoted to int).
2018-03-22 21:13:09 -05:00
Kelvin Sherlock
6a2e3c1abd fix typos and misleading commentary. 2018-03-21 23:05:46 -04:00
Stephen Heumann
73f04eaab4 Add snprintf() and vsnprintf() functions (C99). 2018-03-05 18:52:43 -06:00
Stephen Heumann
8562842f66 sprintf/vsprintf should write a terminating null character even if the string produced is empty.
They were just not writing anything in this case.
2018-03-05 18:02:36 -06:00
Stephen Heumann
62f6b712e7 Add support for 'F', 'a', and 'A' conversion specifiers for scanf (C99).
These all behave identically to 'f'. Note that none of these accept the hexadecimal floating-point representation as input, which they should under C99.
2018-02-27 21:39:49 -06:00
Stephen Heumann
a6d7d91f37 Add initial support for 'F', 'a', and 'A' conversion specifiers for printf (C99).
'F' is currently treated identically to 'f'. This should be a correct implementation for 'F' under C99. (It's not quite correct for 'f', which should print "inf" or "nan" in lower case according to C99.)

'A' and 'a' are not correctly formatted (they are currently treated identically to 'E' and 'e', rather than using the hexadecimal floating-point representation specified by C99), but at least they print the number in some form and consume the correct number of bytes so that the stack isn't corrupted and subsequent conversion specifications print the right values.

The floating-point formats are also moved to the top of the list of conversion specifiers to check, which means they are checked last. This should marginally speed up the integer cases.
2018-02-27 21:29:22 -06:00
Stephen Heumann
f58ef8aea3 Add support for 'z', 't', and 'j' length modifiers in printf and scanf (C99).
'z' corresponds to size_t, 't' to ptrdiff_t, and 'j' to intmax_t. In ORCA/C, these are all 32-bit types, so these size modifiers are equivalent to 'l'. (Note that C99/C11 require intmax_t to be at least 64-bit, but that is not currently the case in ORCA/C since there is no 64-bit integer type.)
2018-02-27 18:44:07 -06:00
Stephen Heumann
e3c0c962d4 Revert various stdio changes to make it match the version in the ORCA/C 2.1.1 B3 ORCALib binary on Opus ][.
The reverted changes relate mainly to adding a second character position in the putback buffer, but the library with those changes crashes on basic stdio operations like printing a string.

For now, this patch reverts stdio to a working, tested version. If the reverted changes are valuable, they can be fixed and then reintroduced later.
2018-02-26 22:49:10 -06:00
Stephen Heumann
56b101a214 Change keep location for stdio to be in the obj directory. 2017-10-31 23:09:27 -05:00
Kelvin Sherlock
578bda8439 CR -> LF 2017-10-31 13:14:07 -04:00
mikew50
954c3a02b5 ORCA libraries, from the Opus ][ CD 2017-10-01 18:00:58 -06:00