diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2002-12-18 15:06:36 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2002-12-18 15:06:36 +0000 |
commit | 03516d9efa76720be2b0b8677573a5f93845c2da (patch) | |
tree | e6cda83d0b5f863aaa15ab5bca8c7637fc71d2b4 /src/glut/dos/PC_HW/pc_hw.c | |
parent | c0fc0d4e5f5c246fc2459348a3d114b232d0c545 (diff) |
DOS updates from Daniel Borca.
Diffstat (limited to 'src/glut/dos/PC_HW/pc_hw.c')
-rw-r--r-- | src/glut/dos/PC_HW/pc_hw.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/glut/dos/PC_HW/pc_hw.c b/src/glut/dos/PC_HW/pc_hw.c index 9b30c5808c..867daf89b0 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.2 for DOS/DJGPP
+ * PC/HW routine collection v1.3 for DOS/DJGPP
*
* Copyright (C) 2002 - Borca Daniel
* Email : dborca@yahoo.com
@@ -73,21 +73,25 @@ void *pc_malloc (size_t size) /*
* standard redirection
*/
-static int h_out, h_outbak, h_err, h_errbak;
+#define STDOUT 1
+#define STDERR 2
+
+static char outname[L_tmpnam];
+static int h_out, h_outbak;
+static char errname[L_tmpnam];
+static int h_err, h_errbak;
int pc_open_stdout (void)
{
- 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);
+ tmpnam(outname);
+
+ if ((h_out=open(outname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
+ h_outbak = dup(STDOUT);
+ fflush(stdout);
+ dup2(h_out, STDOUT);
}
- return (h_out = -1);
+
+ return h_out;
}
void pc_close_stdout (void)
@@ -95,35 +99,32 @@ void pc_close_stdout (void) FILE *f;
char *line = alloca(512);
- if (h_out >= 0) {
- dup2(h_outbak, 1);
+ if (h_out > 0) {
+ dup2(h_outbak, STDOUT);
+ close(h_out);
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);
+ f = fopen(outname, "rt");
+ while (fgets(line, 512, f)) {
+ fputs(line, stdout);
}
+ fclose(f);
+
+ remove(outname);
}
}
int pc_open_stderr (void)
{
- 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);
+ tmpnam(errname);
+
+ if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
+ h_errbak = dup(STDERR);
+ fflush(stderr);
+ dup2(h_err, STDERR);
}
- return (h_err = -1);
+
+ return h_err;
}
void pc_close_stderr (void)
@@ -131,18 +132,17 @@ void pc_close_stderr (void) FILE *f;
char *line = alloca(512);
- if (h_err >= 0) {
- dup2(h_errbak, 2);
+ if (h_err > 0) {
+ dup2(h_errbak, STDERR);
+ close(h_err);
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);
+ f = fopen(errname, "rt");
+ while (fgets(line, 512, f)) {
+ fputs(line, stderr);
}
+ fclose(f);
+
+ remove(errname);
}
}
|