summaryrefslogtreecommitdiff
path: root/src/glut/dos/PC_HW/pc_hw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glut/dos/PC_HW/pc_hw.c')
-rw-r--r--src/glut/dos/PC_HW/pc_hw.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/src/glut/dos/PC_HW/pc_hw.c b/src/glut/dos/PC_HW/pc_hw.c
index 09ab461404..9b30c5808c 100644
--- a/src/glut/dos/PC_HW/pc_hw.c
+++ b/src/glut/dos/PC_HW/pc_hw.c
@@ -1,5 +1,5 @@
/*
- * PC/HW routine collection v1.0 for DOS/DJGPP
+ * PC/HW routine collection v1.2 for DOS/DJGPP
*
* Copyright (C) 2002 - Borca Daniel
* Email : dborca@yahoo.com
@@ -12,7 +12,6 @@
#include <sys/stat.h> /* for mode definitions */
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
#include "pc_hw.h"
@@ -74,68 +73,76 @@ void *pc_malloc (size_t size)
/*
* standard redirection
*/
-static char errname[L_tmpnam];
-static char outname[L_tmpnam];
+static int h_out, h_outbak, h_err, h_errbak;
-static int h_out, h_outbak;
-static int h_err, h_errbak;
-
-void pc_open_stderr (void)
+int pc_open_stdout (void)
{
- if (tmpnam(errname)) {
- h_err = open(errname, O_WRONLY |/* O_BINARY |*/ O_CREAT | O_TRUNC,
- S_IREAD | S_IWRITE);
- h_errbak = dup(2);
- fflush(stderr);
- dup2(h_err, 2);
+ if ((h_out=open(tmpnam(NULL), O_WRONLY | O_CREAT | O_TRUNC | O_TEXT | O_TEMPORARY, S_IRUSR | S_IWUSR)) >= 0) {
+ if ((h_outbak=dup(1)) != -1) {
+ fflush(stdout);
+ if (dup2(h_out, 1) != -1) {
+ return 0;
+ }
+ close(h_outbak);
+ }
+ close(h_out);
}
+ return (h_out = -1);
}
-void pc_close_stderr (void)
+void pc_close_stdout (void)
{
FILE *f;
char *line = alloca(512);
-
- dup2(h_errbak, 2);
- close(h_err);
- close(h_errbak);
-
- if ((f=fopen(errname, "r"))!=NULL) {
- while (fgets(line, 512, f)) {
- fputs(line, stderr);
+
+ if (h_out >= 0) {
+ dup2(h_outbak, 1);
+ close(h_outbak);
+
+ if ((f=fdopen(h_out, "r")) != NULL) {
+ fseek(f, 0, SEEK_SET);
+ while (fgets(line, 512, f)) {
+ fputs(line, stdout);
+ }
+ fclose(f);
+ } else {
+ close(h_out);
}
- fclose(f);
}
-
- remove(errname);
}
-void pc_open_stdout (void)
+int pc_open_stderr (void)
{
- if (tmpnam(outname)) {
- h_out = open(outname, O_WRONLY |/* O_BINARY |*/ O_CREAT | O_TRUNC,
- S_IREAD | S_IWRITE);
- h_outbak = dup(1);
- fflush(stdout);
- dup2(h_out, 1);
+ if ((h_err=open(tmpnam(NULL), O_WRONLY | O_CREAT | O_TRUNC | O_TEXT | O_TEMPORARY, S_IRUSR | S_IWUSR)) >= 0) {
+ if ((h_errbak=dup(2)) != -1) {
+ fflush(stderr);
+ if (dup2(h_err, 2) != -1) {
+ return 0;
+ }
+ close(h_errbak);
+ }
+ close(h_err);
}
+ return (h_err = -1);
}
-void pc_close_stdout (void)
+void pc_close_stderr (void)
{
FILE *f;
char *line = alloca(512);
-
- dup2(h_outbak, 1);
- close(h_out);
- close(h_outbak);
-
- if ((f=fopen(outname, "r"))!=NULL) {
- while (fgets(line, 512, f)) {
- fputs(line, stdout);
+
+ if (h_err >= 0) {
+ dup2(h_errbak, 2);
+ close(h_errbak);
+
+ if ((f=fdopen(h_err, "r")) != NULL) {
+ fseek(f, 0, SEEK_SET);
+ while (fgets(line, 512, f)) {
+ fputs(line, stderr);
+ }
+ fclose(f);
+ } else {
+ close(h_err);
}
- fclose(f);
}
-
- remove(outname);
}