Commit Graph

18 Commits

Author SHA1 Message Date
Stephen Heumann
6635346ae8 Implement llabs and imaxabs functions.
These give the absolute value of 64-bit numbers.
2021-02-06 00:11:44 -06:00
Stephen Heumann
b072f5d042 Implement lldiv and imaxdiv functions.
These do 64-bit division and return a struct with the quotient and remainder.
2021-02-05 18:11:37 -06:00
Stephen Heumann
717cf99071 Detect invalid base values in strtol and strtoul.
They will now return 0 and set errno to EINVAL if an invalid base value (anything other than 0 or 2..36) is detected.

This behavior is required by POSIX. It's not required by the C standards (which leave the behavior in this case undefined), but it seems reasonable to do.
2020-02-17 17:39:36 -06:00
Stephen Heumann
e5360c9605 Spellcheck comments. 2020-02-16 13:29:53 -06:00
Stephen Heumann
8490da9d85 Allow -2147483648 (LONG_MIN) as valid input to strtol(), not setting errno.
This is what other implementations do and seems to be the intent of the standards, although the wording isn't entirely clear.
2020-01-24 12:25:01 -06:00
Stephen Heumann
14554fcdc7 Make strtol() and strtoul() set the right end pointer in error cases.
Previously, they often did not do this. Now they do, as follows:

If there was a sequence of the expected numeric form, then they fully parse that sequence and give a pointer past the end of it, even if the number was out of range.  If there was not a sequence of the expected form, they give the starting pointer that they were passed in.
2020-01-23 23:47:55 -06:00
Stephen Heumann
ebbb5b73ed Allow strtoul to take numbers with a minus sign.
The effect of this is to negate the number in the unsigned long type before returning it.
2020-01-23 21:50:11 -06:00
Stephen Heumann
599c1e3c7b Fix problem where strtol would accept invalid strings like "- +53".
This stemmed from its calling strtoul internally, causing it to accept extra while space and/or + signs. The fix is to have an alternate entry point for strtoul that skips that processing.
2020-01-23 20:42:25 -06:00
Stephen Heumann
ee1b7e606d Implement quick_exit() and at_quick_exit() from C11.
Also, make all the exit functions quit via RTL if #pragma rtl was used. This fixes #19.
2020-01-23 18:43:20 -06:00
Stephen Heumann
887d66d537 Implement aligned_alloc function (C11).
This allocates memory with a specified alignment. Currently, the only allowed alignment value is 1.
2020-01-12 18:54:07 -06:00
Stephen Heumann
571c601b66 strtoul: return 0 when given an empty string, as required by the C standards.
The issue was introduced in commit 6e9790667.

errno is now set to EINVAL in this case. (This is not required by the C standards, but is consistent with various other implementations.)

This fixes the cases in #23 related to strtol() and strtoul().
2019-06-16 20:26:13 -05:00
Stephen Heumann
7a20f5f71d strtoul: don't try to parse initial '0x' as hex prefix unless base is 0 or 16.
In other bases, the 'x' either ends parsing of the number string or (in base 34 and larger) is a digit.

Also, ensure only ASCII characters (with high bit clear) are accepted in all situations.
2018-09-13 18:28:02 -05:00
Stephen Heumann
27fc6836cc Fix div() and ldiv() to return properly-signed remainders.
They could previously give the wrong sign on the remainder in certain cases where one or both of the arguments were negative, because they were using the wrong condition to decide whether to negate it.
2018-09-10 17:09:28 -05:00
Stephen Heumann
efab82784d Add _Exit() function from C99.
This exits the programs without calling atexit functions and possibly without doing other clean-up operations. In ORCA/C, it is functionally identical to _exit().
2018-09-09 23:23:19 -05:00
Stephen Heumann
6e97906678 Make strtol/strtoul return LONG_MIN/LONG_MAX/ULONG_MAX for out-of-range values.
This fixes #10.

There are still issues with the end pointer value generated in error cases.
2018-03-13 22:11:40 -05:00
Stephen Heumann
7abdfc9beb Make system(NULL) detect whether a command processor is available.
Previously, it just ran an Execute shell call with NULL as the command-line pointer.

The fix is to still call Execute, but with an empty string as the command line, and then check if the call gave an error. If running under plain GS/OS, this gives an error for an unknown system call, whereas both ORCA/APW and GNO shells will return with no error in this case. (Golden Gate doesn't implement the Execute shell call, so it also gives an error and will report no command processor available.)

This fixes issue #25.
2018-03-13 17:49:49 -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