}
if (file_extension[0] == '.') {
+ // LCOV_EXCL_START
_E("The file extention includes the leading dot('.')");
return MIME_TYPE_ERROR_INVALID_PARAMETER;
+ // LCOV_EXCL_STOP
}
std::string file_name = "." + std::string(file_extension);
auto xdg_mime_type = content::XdgMime::GetMimeTypeFromFileName(file_name);
if (xdg_mime_type.empty()) {
+ // LCOV_EXCL_START
_E("GetMimeTypeFromFileName(%s) is failed", file_name.c_str());
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
*mime_type = strdup(xdg_mime_type.c_str());
if (*mime_type == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+ // LCOV_EXCL_STOP
}
return MIME_TYPE_ERROR_NONE;
auto file_names = content::XdgMime::GetFileNamesFromMimeType(mime_type);
if (file_names.size() == 0) {
+ // LCOV_EXCL_START
_E("GetFileNameFromMimeType(%s) is failed", mime_type);
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
auto** extensions = reinterpret_cast<char**>(
calloc(file_names.size(), sizeof(char*)));
if (extensions == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+ // LCOV_EXCL_STOP
}
int index = 0;
std::string extension = file_name.substr(pos + 1);
extensions[index] = strdup(extension.c_str());
if (extensions[index] == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
for (int i = 0; i < index; ++i)
free(extensions[i]);
free(extensions);
return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+ // LCOV_EXCL_STOP
}
index++;
}
if (access(file_path, R_OK) < 0) {
+ // LCOV_EXCL_START
if (errno == EACCES) {
_E("Permission denied");
return MIME_TYPE_ERROR_PERMISSION_DENIED;
_E("access() is failed. path(%s), errno(%d)", file_path, errno);
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
struct stat statbuf;
int ret = stat(file_path, &statbuf);
if (ret != 0) {
+ // LCOV_EXCL_START
_E("stat() is failed. path(%s), errno(%d)", file_path, errno);
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
if (!S_ISREG(statbuf.st_mode)) {
+ // LCOV_EXCL_START
_E("%s is not regular file", file_path);
return MIME_TYPE_ERROR_INVALID_PARAMETER;
+ // LCOV_EXCL_START
}
auto xdg_mime_type = content::XdgMime::GetMimeTypeForFile(file_path);
if (xdg_mime_type.empty()) {
+ // LCOV_EXCL_START
_E("GetMimeTypeForFile(%s) is failed", file_path);
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_START
}
*mime_type = strdup(xdg_mime_type.c_str());
if (*mime_type == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+ // LCOV_EXCL_START
}
return MIME_TYPE_ERROR_NONE;
auto xdg_mime_type = content::XdgMime::GetMimeTypeForData(data, len);
if (xdg_mime_type.empty()) {
+ // LCOV_EXCL_START
_E("GetMimeTypeForData() is failed");
return MIME_TYPE_ERROR_IO_ERROR;
+ // LCOV_EXCL_START
}
*mime_type = strdup(xdg_mime_type.c_str());
if (*mime_type == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
return MIME_TYPE_ERROR_OUT_OF_MEMORY;
+ // LCOV_EXCL_START
}
return MIME_TYPE_ERROR_NONE;
std::string XdgMime::GetMimeTypeFromFileName(const std::string& file_name) {
auto* mime_type = xdg_mime_get_mime_type_from_file_name(file_name.c_str());
if (mime_type == nullptr)
- return {};
+ return {}; // LCOV_EXCL_LINE
return std::string(mime_type);
}
auto* mime_type = xdg_mime_get_mime_type_for_file(file_path.c_str(),
&statbuf);
if (mime_type == nullptr)
- return {};
+ return {}; // LCOV_EXCL_LINE
return std::string(mime_type);
}
int result_prio;
auto* mime_type = xdg_mime_get_mime_type_for_data(data, len, &result_prio);
if (mime_type == nullptr)
- return {};
+ return {}; // LCOV_EXCL_LINE
return std::string(mime_type);
}