Skip to content

Commit

Permalink
HostFS: Fix behavior of realpath() on Windows. Clear carry flag on re…
Browse files Browse the repository at this point in the history
…turn from hostfs ACPTR (commanderx16#479)

* Windows needs an additional check for resolved path to indicate that a file does not exist

* fix sequential read problems from BASIC, generalize realpath() for Windows

* fix Windows realpath function to handle non-NULL second arg properly
  • Loading branch information
mooinglemur authored Feb 8, 2023
1 parent c38aa8b commit 06816b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/ieee.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "glue.h"
#ifdef __MINGW32__
#include <direct.h>
// realpath doesn't exist on Windows, but _fullpath is similar enough
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
// Windows just has to be different
#define localtime_r(S,D) !localtime_s(D,S)
#endif
Expand Down Expand Up @@ -79,6 +77,22 @@ typedef struct {

channel_t channels[16];

#ifdef __MINGW32__
// realpath doesn't exist on Windows. This function implements its behavior.
static char *
realpath(const char *path, char *resolved_path) {
char *ret = _fullpath(resolved_path, path, PATH_MAX);

if (ret && _access(ret,0) && errno == ENOENT) {
if (resolved_path == NULL)
free(ret);
return NULL;
}

return ret;
}
#endif

// Prototypes for some of the static functions

static void clear_error();
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ handle_ieee_intercept()
break;
case 0xFFA5:
s=ACPTR(&a);
status = (status & ~2) | (!a << 1);
status = (status & ~3) | (!a << 1); // unconditional CLC, and set zero flag based on byte read
break;
case 0xFFA8:
s=CIOUT(a);
Expand Down

0 comments on commit 06816b5

Please sign in to comment.