Skip to content

Commit bb84e54

Browse files
-
1 parent ea86a74 commit bb84e54

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

base/compv_fileutils.cxx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,38 +259,48 @@ COMPV_IMAGE_FORMAT CompVFileUtils::getImageFormat(const char* pcPath)
259259
}
260260
}
261261

262-
COMPV_ERROR_CODE CompVFileUtils::read(const char* pcPath, CompVBufferPtrPtr buffer)
262+
COMPV_ERROR_CODE CompVFileUtils::read(const char* pcPath, CompVBufferPtrPtr buffer, bool quiet COMPV_DEFAULT(false))
263263
{
264264
COMPV_CHECK_EXP_RETURN(!pcPath || !buffer, COMPV_ERROR_CODE_E_INVALID_PARAMETER);
265265
CompVBufferPtr buffer_ = NULL;
266266
size_t size_ = CompVFileUtils::getSize(pcPath);
267267
if (!size_) {
268-
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "File at %s is empty or doesn't exist", pcPath);
268+
if (!quiet) {
269+
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "File at %s is empty or doesn't exist", pcPath);
270+
}
269271
return COMPV_ERROR_CODE_E_FAILED_TO_READ_FILE;
270272
}
271273
else {
272274
FILE* file_ = nullptr;
273275
void* mem_ = nullptr;
274276
if (!(file_ = CompVFileUtils::open(pcPath, "rb"))) {
275-
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Can't open %s", pcPath);
277+
if (!quiet) {
278+
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Can't open %s", pcPath);
279+
}
276280
return COMPV_ERROR_CODE_E_FILE_NOT_FOUND;
277281
}
278282
mem_ = CompVMem::malloc(size_ + 1);
279283
if (!mem_) {
280-
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Failed to alloc mem with size = %zu", size_);
284+
if (!quiet) {
285+
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Failed to alloc mem with size = %zu", size_);
286+
}
281287
fclose(file_);
282288
return COMPV_ERROR_CODE_E_OUT_OF_MEMORY;
283289
}
284290
size_t read_;
285291
if (size_ != (read_ = fread(mem_, 1, size_, file_))) {
286-
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "fread(%s) returned %zu instead of %zu", pcPath, read_, size_);
292+
if (!quiet) {
293+
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "fread(%s) returned %zu instead of %zu", pcPath, read_, size_);
294+
}
287295
fclose(file_);
288296
CompVMem::free(&mem_);
289297
return COMPV_ERROR_CODE_E_FAILED_TO_READ_FILE;
290298
}
291299
*(reinterpret_cast<char*>(mem_) + size_) = '\0'; //!\ required when reading sources to avoid garbage (e.g OpenCL source *.cl)
292300
if (COMPV_ERROR_CODE_IS_NOK(CompVBuffer::newObjAndTakeData(&mem_, size_, &buffer_))) {
293-
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Failed to create new CompVBuffer object");
301+
if (!quiet) {
302+
COMPV_DEBUG_ERROR_EX(kModuleNameFileUtils, "Failed to create new CompVBuffer object");
303+
}
294304
}
295305
fclose(file_);
296306
CompVMem::free(&mem_);

base/include/compv/base/compv_fileutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class COMPV_BASE_API CompVFileUtils
3232
static size_t getSize(const char* pcPath);
3333
static std::string getExt(const char* pcPath);
3434
static COMPV_IMAGE_FORMAT getImageFormat(const char* pcPath);
35-
static COMPV_ERROR_CODE read(const char* pcPath, CompVBufferPtrPtr buffer);
35+
static COMPV_ERROR_CODE read(const char* pcPath, CompVBufferPtrPtr buffer, bool quiet = false);
3636
static FILE* open(const char* fname, const char* mode);
3737
static COMPV_ERROR_CODE close(FILE** file);
3838
static COMPV_ERROR_CODE write(const char* pcPath, const void* data, size_t count);

0 commit comments

Comments
 (0)