/* * PC/HW routine collection v1.3 for DOS/DJGPP * * Copyright (C) 2002 - Borca Daniel * Email : dborca@yahoo.com * Web : http://www.geocities.com/dborca */ #include #include #include /* for mode definitions */ #include #include #include #include "pc_hw.h" /* * atexit */ #define MAX_ATEXIT 32 static volatile int atexitcnt; static VFUNC atexittbl[MAX_ATEXIT]; static void __attribute__((destructor)) doexit (void) { while (atexitcnt) atexittbl[--atexitcnt](); } int pc_clexit (VFUNC f) { int i; for (i=0;i 0) { h_outbak = dup(STDOUT_FILENO); fflush(stdout); dup2(h_out, STDOUT_FILENO); } return h_out; } void pc_close_stdout (void) { FILE *f; char *line = alloca(512); if (h_out > 0) { dup2(h_outbak, STDOUT_FILENO); close(h_out); close(h_outbak); f = fopen(outname, "rt"); while (fgets(line, 512, f)) { fputs(line, stdout); } fclose(f); remove(outname); } } int pc_open_stderr (void) { tmpnam(errname); if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) { h_errbak = dup(STDERR_FILENO); fflush(stderr); dup2(h_err, STDERR_FILENO); } return h_err; } void pc_close_stderr (void) { FILE *f; char *line = alloca(512); if (h_err > 0) { dup2(h_errbak, STDERR_FILENO); close(h_err); close(h_errbak); f = fopen(errname, "rt"); while (fgets(line, 512, f)) { fputs(line, stderr); } fclose(f); remove(errname); } }