Commit Graph

25 Commits

Author SHA1 Message Date
Shuhei Matsumoto
b78e763c1a string: spdk_strtol to delegate additional error checking
Error check of strtol is left to users of it. But some use cases
of strtol in SPDK do not have enough error check yet.

For example, strtol returns 0 if there were no digits at all.

It should be avoided for each use case to add enough error checking
for strtol.

Hence spdk_strtol and spdk_strtoll do additional error checking
according to the description of manual of strtol.

Besides, there is no use case of negative number now, and to keep
simplicity, spdk_trtol and spdk_strtoll allows only strings that
is positive number or zero.

As a result of this policy, callers of them only have to check if
the return value is not negative.

Subsequent patches will replace atoi to spdk_strtol because atoi
does not have error check.

Change-Id: If3d549970595e53b1141674e47710fe4dd062bc5
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/441626
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
2019-01-29 00:10:57 +00:00
Shuhei Matsumoto
8adbd90991 util/string: sprintf_append_realloc to concatenate strings with realloc
Appending string by using sprintf with realloc will be generally
usable and add sprintf_append_realloc() and vsprintf_append_realloc()
to the utility.

These APIs follow realloc about buffer management, i.e., the original
buffer is left untouched if they fail.

Besides, the original buffer is NULL, they are equivalent to
sprintf_alloc() and vsprintf_alloc(), respectively.

Change-Id: I8b69d9640e86e1862ddd3917995bad6f59426b7e
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Signed-off-by: Chunyang Hui <chunyang.hui@intel.com>
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/436913
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
2019-01-14 21:22:56 +00:00
Pawel Wodkowski
7818939c6d util: make spdk_parse_ip_addr return -EINVAL instead -1
Change-Id: Idcdaeb5603c5fbe369884ced52e569cc3149be39
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/429228
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2018-10-12 23:34:27 +00:00
Jim Harris
cccc940efa string: escape references to \r and \n
Without these escapes, \r and \n don't show up in the
HTML output, and Doxygen throws a warning.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I6bbb8cf5b461999572077cc7381901ca3982d674

Reviewed-on: https://review.gerrithub.io/415856
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
2018-06-19 15:18:08 +00:00
Yanbo Zhou
19354d966c include/string.h: add comments for public APIs
Change-Id: I56488b61ff000070c430851c9627fa23c164fb18
Signed-off-by: Yanbo Zhou <yanbo.zhou@intel.com>
Reviewed-on: https://review.gerrithub.io/406924
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2018-05-17 23:01:00 +00:00
Daniel Verkamp
d81f3dfd3e util: add spdk_mem_all_zero() function
Unify several similar functions checking for a buffer of all zero bytes
into the util library.

Change-Id: Idfbeffa22add34ac9ed1bd75ee27d6bd8b188940
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/400892
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2018-02-23 10:05:32 -05:00
Pawel Wodkowski
891c12a63c util: add spdk_strerror() wrapper with TLS support
This patch remove need for additional buffer when translating error code
to string.

Change-Id: Iaa60088b5c450581d3cdddbb425119b17d55a44b
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/386114
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2018-01-04 15:00:09 -05:00
Daniel Verkamp
71db3a0870 util: make spdk_strerror_r() return void
Handle the possibility of the system strerror_r() returning an error
internally within spdk_strerror_r() so that callers don't need to check
the return value.

Change-Id: I0571c3f5999873575562d08a04d714716a7881ff
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/393105
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2018-01-03 14:04:59 -05:00
Dariusz Stojaczyk
ec6a1afbdb util: add a helper function for parsing capacities (1K, 128M, 2G)
Also used it in parsing `-m` SPDK app param,
meaning that it can now accept numbers
followed by a binary prefix - like 512M or 2G.

Change-Id: If458dc08429237f2cb3f3f661bcaf382468df0f0
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/391670
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2017-12-13 21:19:53 -05:00
Seth Howell
4d43844f4d lib: replace strerror with strerror_r
replaces all references to strerror in the spdk lib directory with
references to the thread safe strerror_r

Change-Id: I80d946cce3299007ee10500b93f7e1c8e503ee41
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/374012
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-08-15 16:47:01 -04:00
Daniel Verkamp
16c362a8de string: add spdk_str_chomp() function
Add a helper function to remove trailing newlines.

Change-Id: I8b1a2bf3d70ef17e0bc7e74429ac955c68cb6bcf
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/370592
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
2017-08-01 13:42:26 -04:00
Daniel Verkamp
45cab335bc include: move standard includes into spdk/stdinc.h
This is the first step toward isolating standard C and POSIX headers
into a single replaceable header file.

Change-Id: I527297f5e7260b01103018ad3429922962ee9add
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-05-08 10:11:01 -07:00
Daniel Verkamp
4404793d09 string: make spdk_parse_ip_addr() params non-const
The host and port output parameters point into the (non-const) char *ip,
so it makes more sense for them to be non-const as well.

This allows the flexibility to pass non-const char pointers as the
output parameters, which will be used in the nvmf_tgt/conf.c parsing
code.

Change-Id: I1d5b102fc389c06d36432904e4fda944437b659e
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2017-02-14 10:28:29 -07:00
Ben Walker
08238af7ee util: Add a function to parse ip addresses.
This function parses in place by inserting null terminators.

Change-Id: I61cb97b87ec05d0183fbaa993fd3d7580a188bde
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
2017-02-07 17:12:38 -07:00
Daniel Verkamp
b4bd76bc63 util: add vsprintf version of spdk_sprintf_alloc
-Wformat-nonliteral needs to be disabled since clang triggers it on the
call to vsnprintf() now that it is nested two calls deep.

Change-Id: I228b9d099cfc2b65181941cbb4798b7f8eae3baa
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-11-22 11:52:00 -07:00
Daniel Verkamp
ae6fbf1d2d util: add spdk_strlen_pad() function
This is a counterpart to spdk_strcpy_pad() which determines the length
of a string in a fixed-size buffer that may be right-padded with a
specific character.

Change-Id: I2dab8d218ee9d55f7c264daa3956c2752d9fc7f7
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-11-22 11:36:34 -07:00
Daniel Verkamp
98c8867e5a scsi: move spdk_strcpy_pad() into util/string.c
This will be useful outside of the SCSI code, so put it in the common
string utility file.

Also reorder the parameters so they match the order used in strncpy().

Change-Id: I9e25a59b64e4bedf04e5a96de463b1d8aa0ddac3
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-08-22 08:58:07 -07:00
Daniel Verkamp
8eafb6546c doc: add Doxygen file marker to all public headers
For existing \file markers, move them to the top of the header and tweak
the wording for consistency.

Change-Id: Icce748effe4dbe97d79a8c87d31caf0ee5797058
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-05-04 11:17:17 -07:00
Daniel Verkamp
d0cbec4a19 lib/util: add spdk_str_trim()
Function to trim leading and trailing whitespace from a string.

Originally based on code imported from istgt.

Change-Id: I87abe584130bdf4930098fadb8e57291f18eda7f
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-05-04 11:17:00 -07:00
Daniel Verkamp
e56aab98ac lib/util: add spdk_strsepq()
Parsing function for delimited strings with embedded quotes.

Originally based on code imported from istgt.

Change-Id: I448feb53ea232048ed8c68738e12bc3660eb4235
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-05-04 11:17:00 -07:00
Daniel Verkamp
c5611b26b3 lib/util: add spdk_strlwr()
Add function to convert string to lowercase in place.

Originally based on code imported from istgt.

Change-Id: Ica9fe2208e6ee09b22c9a652a33c5affe5be23cc
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-05-04 11:17:00 -07:00
Daniel Verkamp
04adec22bc Add extern "C" wrapper to all public headers
Also consistently place the extern "C" before any includes or other
declarations in files that already had it.

Change-Id: Ia316d5be3e509ec76c4a98cfa90ed516073351e0
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-02-12 07:52:35 -07:00
Daniel Verkamp
40c591eac8 string: add spdk_ prefix
sprintf_alloc() -> spdk_sprintf_alloc()

Change-Id: I24970baa37615633572d132abe3e57d0889f1a48
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-02-08 14:28:56 -07:00
Daniel Verkamp
c02b179490 Remove year from copyright headers.
Also add a space between Copyright and (c).

The copyright year can be determined using git metadata.

Also remove the duplicated "All rights reserved." - every instance of
this line already has a corresponding "All rights reserved" immediately
below it, except for examples/ioat/kperf/kmod/dma_perf.c, where I have
added it manually.

Performed using this command:

git ls-files | xargs sed -i -e 's/Copyright(c) \(.*\) Intel Corporation. All rights reserved./Copyright (c) Intel Corporation./'

Change-Id: I3779f404966800709024eb1eb66a50068af2716c
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-01-28 08:54:18 -07:00
Daniel Verkamp
92da744700 util: add sprintf_alloc() function
Like sprintf() with automatic buffer allocation.

This should help to avoid fixed-size buffers in
non-performance-sensitive code that formats strings.

Change-Id: I35209ae84014ed5daf41baa5b03af8a5f6b02b8e
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2015-10-06 10:40:51 -07:00