Skip to content

Commit e985e29

Browse files
tkchiaPerditionC
authored andcommitted
fix: GCC port wrongly used libc internal fns. _open _close _lseek
(take 2)
1 parent 19ddce1 commit e985e29

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

include/misc.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,21 @@ int mk_rd_dir(char *param, int (*func) (const char *), char *fctname);
9595
void cutBackslash(char * const s);
9696
int cd_dir(char *param, int cdd, const char * const fctname);
9797
enum OnOff onoffStr(char *line);
98-
#if defined(__TURBOC__) || defined(__GNUC__)
98+
#if defined(__TURBOC__)
99+
#define sfn_open _open
100+
#define dos_close _close
101+
#else
102+
int sfn_open(const char *pathname, int flags);
99103
#if defined(__GNUC__)
100104
#define stricmp strcasecmp
101105
#define strcmpi strcasecmp
102106
#define strnicmp strncasecmp
103107
#define memicmp strncasecmp
104-
#define lseek _lseek
105-
#endif
106-
#define sfn_open _open
107-
#define dos_close _close
108+
int dos_close(int fd);
108109
#else
109-
int sfn_open(const char *pathname, int flags);
110110
#define dos_close _dos_close
111111
#endif
112+
#endif
112113
int dos_read(int fd, void *buf, unsigned int len);
113114
int dos_write(int fd, const void *buf, unsigned int len);
114115
#define sfnfindfirst(path,attrib,ffblk) findfirst(path,attrib,ffblk)

lib/farread.c

+21
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,35 @@ size_t farwrite(int fd, void far*buf, size_t length)
9393
return 0xffff;
9494
return bytes;
9595
}
96+
#endif
9697

98+
#if !defined(__TURBOC__)
9799
int sfn_open(const char *pathname, int flags)
98100
{
101+
#if defined(__GNUC__)
102+
IREGS r;
103+
r.r_ax = 0x3d00 | flags;
104+
r.r_dx = FP_OFF(pathname);
105+
r.r_ds = FP_SEG(pathname);
106+
intrpt(0x21, &r);
107+
return (r.r_flags & 1) ? -1 : (int)r.r_ax;
108+
#else
99109
int handle;
100110
int result = _dos_open(pathname, flags, &handle);
101111
return (result == 0 ? handle : -1);
112+
#endif
102113
}
114+
#endif
103115

116+
#if defined(__GNUC__)
117+
int dos_close(int fd)
118+
{
119+
IREGS r;
120+
r.r_ax = 0x3e00;
121+
r.r_bx = fd;
122+
intrpt(0x21, &r);
123+
return (r.r_flags & 1) ? -1 : 0;
124+
}
104125
#endif
105126

106127
int dos_read(int fd, void *buf, unsigned int len)

suppl/compat/io.h

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#define __IO_H
55

66
#include <unistd.h>
7+
8+
#ifdef __GNUC__
9+
#define _lseek lseek
10+
#endif
11+
712
extern int _open(const char *pathname, int flags, ...);
813
extern int _creat(const char *pathname, mode_t mode);
914
extern int _read(int fd, void *buf, size_t cnt);

0 commit comments

Comments
 (0)