Commit 2284b56b authored by Krzysztof Karas's avatar Krzysztof Karas Committed by Tomasz Zawadzki
Browse files

lib/util: add a function to load data from file



Add a helper function to load data from file name and
return in after closing the file.

Change-Id: If0a69d89e5492b147d4b6672c7a0914eab0752a9
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/21828


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent aa824ae6
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -26,6 +26,16 @@ extern "C" {
 */
void *spdk_posix_file_load(FILE *file, size_t *size);

/**
 * Load content of a given file name into a data buffer.
 *
 * \param file_name File name.
 * \param size Size of bytes read from the file.
 *
 * \return data containing the content on success, NULL on failure.
 */
void *spdk_posix_file_load_from_name(const char *file_name, size_t *size);

#ifdef __cplusplus
}
#endif
+16 −0
Original line number Diff line number Diff line
@@ -41,3 +41,19 @@ spdk_posix_file_load(FILE *file, size_t *size)
	free(buf);
	return NULL;
}

void *
spdk_posix_file_load_from_name(const char *file_name, size_t *size)
{
	FILE *file = fopen(file_name, "r");
	void *data;

	if (file == NULL) {
		return NULL;
	}

	data = spdk_posix_file_load(file, size);
	fclose(file);

	return data;
}
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@

	# public functions in file.h
	spdk_posix_file_load;
	spdk_posix_file_load_from_name;

	# public functions in hexlify.h
	spdk_hexlify;