Skip to content

Commit 618227e

Browse files
committed
util: move nvme_strerror to libraray
This is a useful helper which can be reused inside the library as well. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 0f8351d commit 618227e

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

libnvme/src/libnvme.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ LIBNVME_2_0 {
247247
nvme_skip_namespaces;
248248
nvme_status_to_errno;
249249
nvme_status_to_string;
250+
nvme_strerror;
250251
nvme_submit_admin_passthru;
251252
nvme_submit_io_passthru;
252253
nvme_subsys_filter;

libnvme/src/nvme/util.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ const char *nvme_errno_to_string(int status)
641641
return s;
642642
}
643643

644+
const char *nvme_strerror(int errnum)
645+
{
646+
if (errnum >= ENVME_CONNECT_RESOLVE)
647+
return nvme_errno_to_string(errnum);
648+
return strerror(errnum);
649+
}
650+
644651
#ifdef HAVE_NETDB
645652
int hostname2traddr(struct nvme_global_ctx *ctx, const char *traddr,
646653
char **hostname)

libnvme/src/nvme/util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ const char *nvme_status_to_string(int status, bool fabrics);
9595
*/
9696
const char *nvme_errno_to_string(int err);
9797

98+
/**
99+
* nvme_strerror() - Returns string describing nvme errors and errno
100+
* @err: Returned error codes from all libnvme functions
101+
*
102+
* Return: String representation of either the nvme connect error codes
103+
* (positive values) or errno string (negative values)
104+
*/
105+
const char *nvme_strerror(int errnum);
106+
98107
/**
99108
* nvme_init_ctrl_list() - Initialize an nvme_ctrl_list structure from an array.
100109
* @cntlist: The controller list structure to initialize

nvme.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,6 @@ static OPT_VALS(feature_name) = {
314314
VAL_END()
315315
};
316316

317-
const char *nvme_strerror(int errnum)
318-
{
319-
if (errnum >= ENVME_CONNECT_RESOLVE)
320-
return nvme_errno_to_string(errnum);
321-
return strerror(errnum);
322-
}
323-
324317
static ssize_t getrandom_bytes(void *buf, size_t buflen)
325318
{
326319
ssize_t result;

0 commit comments

Comments
 (0)