Skip to content

Commit

Permalink
win_opendir: remove unused functions, remove struct __dir from header
Browse files Browse the repository at this point in the history
  • Loading branch information
JNechaevsky committed Nov 10, 2024
1 parent a10fe99 commit 04c5610
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 101 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 */
21 changes: 0 additions & 21 deletions win32/win_opendir.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ SOFTWARE.
#ifndef WIN_OPENDIR_H
#define WIN_OPENDIR_H

#include <stdint.h>
#include <sys/types.h>

#ifndef NAME_MAX
Expand Down Expand Up @@ -100,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 04c5610

Please sign in to comment.