MCPcopy Create free account
hub / github.com/csound/csound / FileList_getFileNameString

Function FileList_getFileNameString

Emscripten/src/FileList.c:56–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55
56EMSCRIPTEN_KEEPALIVE
57char *FileList_getFileNameString(const char *directoryPath, size_t fileNumber)
58{
59 if (fileNumber >= FileList_getFileCount(directoryPath)) {
60
61 printf("ERROR: illegal file index");
62 return 0;
63 }
64 else {
65
66 struct dirent *directoryEntry;
67 DIR *directory = opendir(directoryPath);
68 if (directory) {
69
70 size_t currentIndex = 0;
71 while ((directoryEntry = readdir(directory)) != NULL) {
72
73 struct stat st;
74 lstat(directoryEntry->d_name, &st);
75
76 if (S_ISDIR(st.st_mode)) {
77
78 continue;
79 }
80 else {
81 if (currentIndex == fileNumber) {
82
83 closedir(directory);
84 return directoryEntry->d_name;
85 }
86
87 currentIndex++;
88 }
89
90 }
91 }
92
93 }
94
95 return 0;
96}
97

Callers

nothing calls this directly

Calls 2

FileList_getFileCountFunction · 0.85
readdirFunction · 0.85

Tested by

no test coverage detected