Skip to content

Commit

Permalink
add findclose() impl for comcom32 [#92]
Browse files Browse the repository at this point in the history
This doesn't fix all the ff handle leaks.
  • Loading branch information
stsp committed Apr 3, 2024
1 parent 5a08fc7 commit cfdff38
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LINK_OPT =
SRCS = $(SRCDIR)/command.c $(SRCDIR)/cmdbuf.c $(SRCDIR)/ms.c \
$(SRCDIR)/env.c $(SRCDIR)/psp.c $(SRCDIR)/umb.c $(SRCDIR)/ae0x.c \
$(SRCDIR)/compl.c \
$(SRCDIR)/version.c memmem.c fmemcpy.c
$(SRCDIR)/version.c memmem.c fmemcpy.c findclos.c
ASSRCS = $(SRCDIR)/asm.S $(SRCDIR)/int23.S $(SRCDIR)/int0.S $(SRCDIR)/mouse.S
OBJS = $(notdir $(SRCS:.c=.o)) $(notdir $(ASSRCS:.S=.o))
CMD = comcom32.exe
Expand Down
46 changes: 46 additions & 0 deletions 32/findclos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* dj64 - 64bit djgpp-compatible tool-chain
* Copyright (C) 2021-2024 @stsp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <errno.h>
#include <fcntl.h>
#include <dpmi.h>
#include <libc/dosio.h>
#include "findclos.h"

int
findclose(int handle)
{
__dpmi_regs r;
int use_lfn = _USE_LFN;

if (use_lfn)
{
r.x.flags |= 1; /* Always set CF before calling a 0x71NN function. */
r.x.bx = handle;
r.x.ax = 0x71a1;
__dpmi_int(0x21, &r);
if (!(r.x.flags & 1))
return 0;
errno = __doserr_to_errno(r.x.ax);
return errno;
}
return 0;
}

int __attribute__((alias("findclose")))
__findclose(int handle);
7 changes: 7 additions & 0 deletions 32/findclos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef FINDCLOS_H
#define FINDCLOS_H

#define HAVE_FINDCLOSE 1
int findclose(int handle);

#endif
3 changes: 3 additions & 0 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ static inline int file_copytime(int desc_handle, int src_handle)
#include <unistd.h>
#include <sys/exceptn.h>
#include <dpmi.h>
#ifndef DJ64
#include "findclos.h"
#endif

#ifndef USE_CONIO_OUT
#define cprintf printf
Expand Down

0 comments on commit cfdff38

Please sign in to comment.