2 * PC/HW routine collection v1.3 for DOS/DJGPP
4 * Copyright (C) 2002 - Daniel Borca
5 * Email : dborca@yahoo.com
6 * Web : http://www.geocities.com/dborca
12 #include <sys/stat.h> /* for mode definitions */
25 static volatile int atexitcnt
;
26 static VFUNC atexittbl
[MAX_ATEXIT
];
29 static void __attribute__((destructor
))
32 while (atexitcnt
) atexittbl
[--atexitcnt
]();
41 for (i
= 0; i
< atexitcnt
; i
++) {
42 if (atexittbl
[i
] == f
) {
43 for (atexitcnt
--; i
< atexitcnt
; i
++) atexittbl
[i
] = atexittbl
[i
+1];
56 if (atexitcnt
< MAX_ATEXIT
) {
57 atexittbl
[atexitcnt
++] = f
;
65 * locked memory allocation
68 pc_malloc (size_t size
)
70 void *p
= malloc(size
);
73 if (_go32_dpmi_lock_data(p
, size
)) {
84 * standard redirection
86 static char outname
[L_tmpnam
];
87 static int h_out
, h_outbak
;
88 static char errname
[L_tmpnam
];
89 static int h_err
, h_errbak
;
97 if ((h_out
=open(outname
, O_WRONLY
| O_CREAT
| O_TEXT
| O_TRUNC
, S_IREAD
| S_IWRITE
)) > 0) {
98 h_outbak
= dup(STDOUT_FILENO
);
100 dup2(h_out
, STDOUT_FILENO
);
108 pc_close_stdout (void)
111 char *line
= alloca(512);
114 dup2(h_outbak
, STDOUT_FILENO
);
118 f
= fopen(outname
, "rt");
119 while (fgets(line
, 512, f
)) {
130 pc_open_stderr (void)
134 if ((h_err
=open(errname
, O_WRONLY
| O_CREAT
| O_TEXT
| O_TRUNC
, S_IREAD
| S_IWRITE
)) > 0) {
135 h_errbak
= dup(STDERR_FILENO
);
137 dup2(h_err
, STDERR_FILENO
);
145 pc_close_stderr (void)
148 char *line
= alloca(512);
151 dup2(h_errbak
, STDERR_FILENO
);
155 f
= fopen(errname
, "rt");
156 while (fgets(line
, 512, f
)) {