Skip to content

Commit

Permalink
Merge branch 'master' of github.com:chocolate-doom/chocolate-doom
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiangreffrath committed Oct 31, 2024
2 parents 1f4fc04 + bb9bb23 commit d247dbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 100 deletions.
88 changes: 8 additions & 80 deletions win32/win_opendir.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ SOFTWARE.
#define FILE_NAME_NORMALIZED 0
#endif /* FILE_NAME_NORMALIZED */

struct __dir
{
struct dirent *entries;
intptr_t fd;
long int count;
long int index;
};

int closedir(DIR *dirp)
{
struct __dir *data = NULL;
Expand Down Expand Up @@ -327,52 +335,6 @@ DIR *opendir(const char *name)
return dirp;
}

DIR *_wopendir(const wchar_t *name)
{
DIR *dirp = NULL;
wchar_t *wname = __get_buffer();
int size = 0;
if (!wname)
{
errno = ENOMEM;
return NULL;
}
size = (int) wcslen(name);
if (size > NTFS_MAX_PATH)
{
free(wname);
return NULL;
}
memcpy(wname + 4, name, sizeof(wchar_t) * (size + 1));
dirp = __internal_opendir(wname, size + 5);
free(wname);
return dirp;
}

DIR *fdopendir(intptr_t fd)
{
DIR *dirp = NULL;
wchar_t *wname = __get_buffer();
int size = 0;

if (!wname)
{
errno = ENOMEM;
return NULL;
}
size = GetFinalPathNameByHandleW((HANDLE) fd, wname + 4, NTFS_MAX_PATH,
FILE_NAME_NORMALIZED);
if (0 == size)
{
free(wname);
errno = ENOTDIR;
return NULL;
}
dirp = __internal_opendir(wname, size + 5);
free(wname);
return dirp;
}

struct dirent *readdir(DIR *dirp)
{
struct __dir *data = (struct __dir *) dirp;
Expand All @@ -388,38 +350,4 @@ struct dirent *readdir(DIR *dirp)
return NULL;
}

void seekdir(DIR *dirp, long int offset)
{
if (dirp)
{
struct __dir *data = (struct __dir *) dirp;
data->index = (offset < data->count) ? offset : data->index;
}
}

void rewinddir(DIR *dirp)
{
seekdir(dirp, 0);
}

long int telldir(DIR *dirp)
{
if (!dirp)
{
errno = EBADF;
return -1;
}
return ((struct __dir *) dirp)->count;
}

intptr_t dirfd(DIR *dirp)
{
if (!dirp)
{
errno = EINVAL;
return -1;
}
return ((struct __dir *) dirp)->fd;
}

#endif /* _WIN32 */
20 changes: 0 additions & 20 deletions win32/win_opendir.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,12 @@ struct dirent
char d_name[NAME_MAX];
};

struct __dir
{
struct dirent *entries;
intptr_t fd;
long int count;
long int index;
};

int closedir(DIR *dirp);

DIR *opendir(const char *name);

DIR *_wopendir(const wchar_t *name);

DIR *fdopendir(intptr_t fd);

struct dirent *readdir(DIR *dirp);

void seekdir(DIR *dirp, long int offset);

void rewinddir(DIR *dirp);

long int telldir(DIR *dirp);

intptr_t dirfd(DIR *dirp);

#endif /* WIN_OPENDIR_H */

#endif /* _WIN32 */

0 comments on commit d247dbc

Please sign in to comment.