Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use fpurge/__fpurge to cancel buffered output #366

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

olebole
Copy link
Member

@olebole olebole commented Jan 13, 2024

This is an alternative to NOIRLAB IRAFs 48b2f61, which defines fcancel() as setvbuf() on macOS:

iraf/unix/os/zxwhen.c

Lines 90 to 96 in 3761a03

#ifdef MACOSX
#define _IONBF 2 /* No buffering. */
#define fcancel(fp) setvbuf(fp, NULL, _IONBF, 0);
#else
//#define fcancel(fp) ((fp)->_r = (fp)->_w = 0)
#define fcancel(fp)
#endif

setvbuf() is not what fcancel() is supposed to do, namely to cancel any buffered output. Instead, it just makes the output unbuffered. i.e. when applying this patch, stdout will become unbuffered for the rest of the session after ^C. Also, setvbuf() is not macOS specific but part of the standard C library (and therefore also available for Linux). And, hard-coding _IONBF instead of using the proper include file (stdio.h) is bad style.

The better solution (although non-portable) is to use fpurge() on macOS (and BSD variants), and __fpurge() on Linux (and glibc variants, like HURD). This is done in this PR. While not really portable, these are the libc functions for this task. Linux is covered with the __GLIBC__ macro here, because it is not a Linux but a glibc feature. HURD is handled like Linux.

@mjfitzpatrick, FYI.

While not really portable, these are the libc functions for this
task. Linux is covered with the __GLIBC__ macro here, because it is
not a Linux but a glibc feature. HURD is handled like Linux.
@olebole olebole merged commit 3b72208 into iraf-community:main Jan 29, 2024
3 checks passed
@olebole olebole deleted the purge-on-ctrlc branch January 29, 2024 20:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant