in src/for_each_in_sub_folder.c [21:76]
static int on_subfolder_folder(const char* folder, const WIN32_FIND_DATAA* findData, void* context, bool* enumerationShouldContinue)
{
int result;
/*see if findData is about a folder*/
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_006: [ If findData does not have FILE_ATTRIBUTE_DIRECTORY flag set then on_subfolder_folder shall set enumerationShouldContinue to true, succeed, and return 0. ]*/
if (!(findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
result = 0;
*enumerationShouldContinue = true;
}
else
{
if (
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_007: [ If findData->cFileName is "." then on_subfolder_folder shall set enumerationShouldContinue to true, succeed, and return 0. ]*/
(strcmp(findData->cFileName, ".") == 0) ||
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_013: [ If findData->cFileName is ".." then on_subfolder_folder shall set enumerationShouldContinue to true, succeed, and return 0. ]*/
(strcmp(findData->cFileName, "..") == 0)
)
{
result = 0;
*enumerationShouldContinue = true;
}
else
{
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_008: [ on_subfolder_folder shall assemble a string folder\findData->cFileName. ]*/
char* subfolder = sprintf_char("%s\\%s", folder, findData->cFileName);
if (subfolder == NULL)
{
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_010: [ If there are any failures then on_subfolder_folder shall fail and return a non-zero value. ]*/
LogError("failure in sprintf_char");
result = MU_FAILURE;
}
else
{
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_009: [ on_subfolder_folder shall call for_each_in_folder with folder set to the previous string, on_each_in_folder set to the original on_each_in_folder passed to for_each_in_sub_folder and context set to the original context passed to for_each_in_sub_folder. ]*/
FOR_EACH_IN_SUBFOLDER* forEachInSubfolder = context;
if (for_each_in_folder(subfolder, forEachInSubfolder->user_on_each_in_folder, forEachInSubfolder->user_context) != 0)
{
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_010: [ If there are any failures then on_subfolder_folder shall fail and return a non-zero value. ]*/
LogError("failure in for_each_in_folder folder=%s, subfolder=%s", folder, subfolder);
result = MU_FAILURE;
}
else
{
/*Codes_SRS_FOR_EACH_IN_SUBFOLDER_02_011: [ on_subfolder_folder shall set enumerationShouldContinue to true, succeed and return 0. ]*/
result = 0;
*enumerationShouldContinue = true;
}
free(subfolder);
}
}
}
return result;
}