ORCALib
Go to file
Stephen Heumann 16c7952648 fclose: close stream even if there is an error flushing buffered data.
This can happen, e.g., if there is an IO error or if there is insufficient free disk space to flush the data. In this case, fclose should return -1 to report an error, but it should still effectively close the stream and deallocate the buffer for it. (This behavior is explicitly specified in the C99 and later standards.)

Previously, ORCA/C effectively left the stream open in these cases. As a result, the buffer was not deallocated. More importantly, this could cause the program to hang at exit, because the stream would never be removed from the list of open files.

Here is an example program that demonstrates the problem:

/*
 * Run this on a volume with less than 1MB of free space, e.g. a floppy.
 * The fclose return value should be -1 (EOF), indicating an error, but
 * the two RealFreeMem values should be close to each other (indicating
 * that the buffer was freed), and the program should not hang on exit.
 */

#include <stdio.h>
#include <stddef.h>
#include <memory.h>

#define BUFFER_SIZE 1000000

int main(void) {
        size_t i;
        int ret;

        printf("At start, RealFreeMem = %lu\n", RealFreeMem());

        FILE *f = fopen("testfile", "wb");
        if (!f)
                return 0;

        setvbuf(f, NULL, _IOFBF, BUFFER_SIZE);

        for (i = 0; i < BUFFER_SIZE; i++) {
                putc('x', f);
        }

        ret = fclose(f);
        printf("fclose return value = %d\n", ret);

        printf("At end, RealFreeMem = %lu (should be close to start value)\n",
                RealFreeMem());
}
2024-02-19 22:30:15 -06:00
obj ORCA libraries, from the Opus ][ CD 2017-10-01 18:00:58 -06:00
LICENSE ORCA libraries, from the Opus ][ CD 2017-10-01 18:00:58 -06:00
README.md ORCA libraries, from the Opus ][ CD 2017-10-01 18:00:58 -06:00
assert.asm Add __assert2 function to include the function name when reporting assertion failures. 2021-08-24 18:21:39 -05:00
assert.macros assert - use updated ph2/ph4 macros that support pei dp vs lda dp / pha. 2018-06-27 23:36:02 -04:00
backup CR -> LF 2017-10-31 13:14:07 -04:00
cc.asm Save a few bytes in the startup code. 2023-03-28 21:38:55 -05:00
cc.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
ctype.asm Standardize indentation using spaces. 2022-06-25 18:27:20 -05:00
equates.asm Restore changes to allow ungetc of byte values 0x80 through 0xFF. 2022-06-27 17:58:23 -05:00
fcntl.asm lseek: make seeking to an offset before end of file work properly. 2022-07-14 18:34:24 -05:00
fcntl.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
int64.asm Remove floating-point code from ORCALib. 2023-06-23 15:52:46 -05:00
int64.macros Remove floating-point code from ORCALib. 2023-06-23 15:52:46 -05:00
locale.asm Add an implementation of the <locale.h> functions. 2021-09-30 18:34:54 -05:00
locale.macros Add an implementation of the <locale.h> functions. 2021-09-30 18:34:54 -05:00
m16.int64 Use some improved macros for 64-bit operations in the libraries. 2021-02-12 20:24:37 -06:00
make Remove floating-point code from ORCALib. 2023-06-23 15:52:46 -05:00
orca.asm Change several JMP instructions to BRL. 2023-06-19 18:05:46 -05:00
orca.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
setjmp.asm CR -> LF 2017-10-31 13:14:07 -04:00
settypes Add script to set filetypes. 2023-08-06 17:48:41 -05:00
signal.asm Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
signal.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
smac CR -> LF 2017-10-31 13:14:07 -04:00
stdio.asm fclose: close stream even if there is an error flushing buffered data. 2024-02-19 22:30:15 -06:00
stdio.macros Remove floating-point code from ORCALib. 2023-06-23 15:52:46 -05:00
stdlib.asm Small optimizations in library code. 2024-02-18 17:35:21 -06:00
stdlib.macros Avoid excessively deep recursion in qsort. 2023-02-15 22:04:10 -06:00
string.asm strncmp: Fix issues related to very large n values. 2024-02-19 22:12:26 -06:00
string.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
time.asm Fix stack handling in localtime. 2023-01-05 20:00:44 -06:00
time.macros Compute tm_yday and tm_wday directly in ~gmlocaltime. 2022-12-31 19:10:36 -06:00
toolglue.asm Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
toolglue.macros Use newer, more efficient ph2/ph4 macros throughout ORCALib. 2022-06-30 19:01:47 -05:00
uchar.asm Add implementation of the <uchar.h> functions. 2021-10-03 16:02:30 -05:00
uchar.macros Add implementation of the <uchar.h> functions. 2021-10-03 16:02:30 -05:00
vars.asm Rename CVars to ~CVars to avoid namespace pollution. 2023-01-02 18:41:45 -06:00
vars.macros CR -> LF 2017-10-31 13:14:07 -04:00

README.md

ORCALib

Libraries for the ORCA language suite (ORCA/C, ORCA/M, ORCA/Pascal) for the Apple IIGS

If you would like to make changes to this compiler and distribute them to others, feel free to submit them here. If the changes apply to the Apple IIGS, they will generally be approved for distribution on the master branch. For changes that retarget the library to generate code for a different platform, the project will either be forked or a new repository will be created, as appropriate.

The general conditions that must be met before a change is released on master are:

  1. The modified library must compile under the currently released version of ORCA/M.

  2. The various languages that make use of the library mush still pass their respective test suites, or changes to those test suites must also be submitted.

Contact support@byteworks.us if you need contributor access.

A complete distribution of the ORCA languages, including installers and documentation, is available from the Juiced GS store at https://juiced.gs/store/category/software/. It is distributed as part of the Opus ][ package.