Skip to content

Commit

Permalink
fix: GCC port wrongly used libc internal fns. _open _close _lseek
Browse files Browse the repository at this point in the history
(take 2)
  • Loading branch information
tkchia authored and PerditionC committed Nov 7, 2021
1 parent 19ddce1 commit e985e29
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ int mk_rd_dir(char *param, int (*func) (const char *), char *fctname);
void cutBackslash(char * const s);
int cd_dir(char *param, int cdd, const char * const fctname);
enum OnOff onoffStr(char *line);
#if defined(__TURBOC__) || defined(__GNUC__)
#if defined(__TURBOC__)
#define sfn_open _open
#define dos_close _close
#else
int sfn_open(const char *pathname, int flags);
#if defined(__GNUC__)
#define stricmp strcasecmp
#define strcmpi strcasecmp
#define strnicmp strncasecmp
#define memicmp strncasecmp
#define lseek _lseek
#endif
#define sfn_open _open
#define dos_close _close
int dos_close(int fd);
#else
int sfn_open(const char *pathname, int flags);
#define dos_close _dos_close
#endif
#endif
int dos_read(int fd, void *buf, unsigned int len);
int dos_write(int fd, const void *buf, unsigned int len);
#define sfnfindfirst(path,attrib,ffblk) findfirst(path,attrib,ffblk)
Expand Down
21 changes: 21 additions & 0 deletions lib/farread.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,35 @@ size_t farwrite(int fd, void far*buf, size_t length)
return 0xffff;
return bytes;
}
#endif

#if !defined(__TURBOC__)
int sfn_open(const char *pathname, int flags)
{
#if defined(__GNUC__)
IREGS r;
r.r_ax = 0x3d00 | flags;
r.r_dx = FP_OFF(pathname);
r.r_ds = FP_SEG(pathname);
intrpt(0x21, &r);
return (r.r_flags & 1) ? -1 : (int)r.r_ax;
#else
int handle;
int result = _dos_open(pathname, flags, &handle);
return (result == 0 ? handle : -1);
#endif
}
#endif

#if defined(__GNUC__)
int dos_close(int fd)
{
IREGS r;
r.r_ax = 0x3e00;
r.r_bx = fd;
intrpt(0x21, &r);
return (r.r_flags & 1) ? -1 : 0;
}
#endif

int dos_read(int fd, void *buf, unsigned int len)
Expand Down
5 changes: 5 additions & 0 deletions suppl/compat/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#define __IO_H

#include <unistd.h>

#ifdef __GNUC__
#define _lseek lseek
#endif

extern int _open(const char *pathname, int flags, ...);
extern int _creat(const char *pathname, mode_t mode);
extern int _read(int fd, void *buf, size_t cnt);
Expand Down

0 comments on commit e985e29

Please sign in to comment.