Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reimplement count_dir for Windows
  • Loading branch information
NoobJsPerson committed Jun 25, 2024
commit b548940e7499bf552e36bd78b0d10f3646b84249
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ static void sig_handler(int _) {
(void)_;
keep_running = 0;
}

#ifdef _WIN32
#define count_dir win_count_dir
#else
int count_dir(char *dir) {
struct dirent *dp;
DIR *fd;
Expand All @@ -241,6 +243,7 @@ int count_dir(char *dir) {

return dir_count;
}
#endif

void print_usage() {
printf("Usage:\n\n"
Expand Down
4 changes: 4 additions & 0 deletions src/runna.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ int exec_compile_output(char *file_path, char *file_name_no_ext) {
closedir(dir);
} else if (ENOENT == errno) {
// need to make BIN_PATH
#ifdef _WIN32
mkdir(BIN_PATH);
#else
mkdir(BIN_PATH, 0700);
#endif
} else {
perror("probing BIN_PATH failed");
}
Expand Down
16 changes: 15 additions & 1 deletion src/windirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ int scandir(
qsort(**namelist, index+1, sizeof(struct dirent), alphasort);
FindClose(hFind);
return 1;
}
}
int win_count_dir(char *dir)
{
int dir_count;
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(dir,&FindFileData);
if (hFind == INVALID_HANDLE_VALUE) return -1;
while(FindNextFile(hFind, &FindFileData)) {
if (!strcmp(FindFileData.cFileName, ".") || !strcmp(FindFileData.cFileName, ".."))
continue; /* skip self and parent */
dir_count++;
}
FindClose(hFind);
return dir_count;
}