summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2012-12-23 11:59:48 -0500
committerOndrej Kos <okos@redhat.com>2013-01-24 08:34:35 +0100
commit360710d1a6c0c24d00a915a630884281b0b9e665 (patch)
tree428e2eee95344570c6ebf8ede39180e5031f1e50
parent9b368a8652b595528dcf85c9ecfeba0d93550ee1 (diff)
downloadding-libs-360710d1a6c0c24d00a915a630884281b0b9e665.tar.gz
ding-libs-360710d1a6c0c24d00a915a630884281b0b9e665.tar.xz
ding-libs-360710d1a6c0c24d00a915a630884281b0b9e665.zip
Use ENOMEM instead of errno
Reviewed all uses or errno. Cleaned places that needed cleaning. Did not remove <errno.h> yet where it is not needed.
-rw-r--r--ini/ini_comment.c2
-rw-r--r--ini/ini_config_ut.c4
-rw-r--r--ini/ini_configobj.c4
-rw-r--r--ini/ini_fileobj.c31
-rw-r--r--ini/ini_parse.c18
5 files changed, 18 insertions, 41 deletions
diff --git a/ini/ini_comment.c b/ini/ini_comment.c
index acf8b66..6b56d02 100644
--- a/ini/ini_comment.c
+++ b/ini/ini_comment.c
@@ -736,7 +736,7 @@ int ini_comment_serialize (struct ini_comment *ic,
error = ini_comment_get_line(ic, i, &commentline, &len);
if (error) {
- TRACE_ERROR_NUMBER("Failed to get line", errno);
+ TRACE_ERROR_NUMBER("Failed to get line", error);
return error;
}
diff --git a/ini/ini_config_ut.c b/ini/ini_config_ut.c
index ab0b1f7..6c2e986 100644
--- a/ini/ini_config_ut.c
+++ b/ini/ini_config_ut.c
@@ -1554,12 +1554,10 @@ int main(int argc, char *argv[])
srcdir = getenv("srcdir");
if(srcdir) {
- errno = 0;
rundir = malloc(strlen(srcdir) + sizeof(inidir));
if (!rundir) {
- error = errno;
printf("Failed to allocate memory to store path"
- " to the test files %d.\n", error);
+ " to the test files %d.\n", ENOMEM);
return -1;
}
diff --git a/ini/ini_configobj.c b/ini/ini_configobj.c
index 7de57e4..e42d4d4 100644
--- a/ini/ini_configobj.c
+++ b/ini/ini_configobj.c
@@ -119,10 +119,8 @@ int ini_config_create(struct ini_cfgobj **ini_config)
return EINVAL;
}
- errno = 0;
new_co = malloc(sizeof(struct ini_cfgobj));
if (!new_co) {
- error = errno;
TRACE_ERROR_NUMBER("Failed to allocate memory", ENOMEM);
return ENOMEM;
}
@@ -263,10 +261,8 @@ int ini_config_copy(struct ini_cfgobj *ini_config,
}
/* Create a new configuration object */
- errno = 0;
new_co = malloc(sizeof(struct ini_cfgobj));
if (!new_co) {
- error = errno;
TRACE_ERROR_NUMBER("Failed to allocate memory", ENOMEM);
return ENOMEM;
}
diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c
index d26add4..1410a90 100644
--- a/ini/ini_fileobj.c
+++ b/ini/ini_fileobj.c
@@ -170,12 +170,10 @@ int ini_config_file_open(const char *filename,
}
/* Allocate structure */
- errno = 0;
new_ctx = malloc(sizeof(struct ini_cfgfile));
if (!new_ctx) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to allocate file ctx.", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to allocate file ctx.", ENOMEM);
+ return ENOMEM;
}
new_ctx->filename = NULL;
@@ -189,13 +187,11 @@ int ini_config_file_open(const char *filename,
new_ctx->count = 0;
/* Construct the full file path */
- errno = 0;
new_ctx->filename = malloc(PATH_MAX + 1);
if (!(new_ctx->filename)) {
- error = errno;
ini_config_file_destroy(new_ctx);
- TRACE_ERROR_NUMBER("Failed to allocate memory for file path.", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to allocate memory for file path.", ENOMEM);
+ return ENOMEM;
}
/* Construct path */
@@ -236,12 +232,10 @@ int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
}
/* Allocate structure */
- errno = 0;
new_ctx = malloc(sizeof(struct ini_cfgfile));
if (!new_ctx) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to allocate file ctx.", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to allocate file ctx.", ENOMEM);
+ return ENOMEM;
}
new_ctx->file = NULL;
@@ -320,13 +314,10 @@ int ini_config_get_errors(struct ini_cfgfile *file_ctx,
return EINVAL;
}
-
- errno = 0;
errlist = calloc(file_ctx->count + 1, sizeof(char *));
if (!errlist) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to allocate memory for errors.", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to allocate memory for errors.", ENOMEM);
+ return ENOMEM;
}
/* Bind iterator */
@@ -365,14 +356,12 @@ int ini_config_get_errors(struct ini_cfgfile *file_ctx,
* are pretty short and will fir into the predefined
* error length buffer.
*/
- errno = 0;
line = malloc(MAX_ERROR_LINE + 1);
if (!line) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to get memory for error.", error);
+ TRACE_ERROR_NUMBER("Failed to get memory for error.", ENOMEM);
col_unbind_iterator(iterator);
ini_config_free_errors(errlist);
- return error;
+ return ENOMEM;
}
snprintf(line, MAX_ERROR_LINE, LINE_FORMAT,
diff --git a/ini/ini_parse.c b/ini/ini_parse.c
index 5d39375..9e81f2d 100644
--- a/ini/ini_parse.c
+++ b/ini/ini_parse.c
@@ -1012,12 +1012,10 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action)
}
/* Dup the key name */
- errno = 0;
po->key = malloc(len + 1);
if (!(po->key)) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to dup key", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to dup key", ENOMEM);
+ return ENOMEM;
}
memcpy(po->key, po->last_read, len);
@@ -1040,12 +1038,10 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action)
TRACE_INFO_NUMBER("LENGTH:", len);
/* Dup the part of the value */
- errno = 0;
dupval = malloc(len + 1);
if (!dupval) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to dup value", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to dup value", ENOMEM);
+ return ENOMEM;
}
memcpy(dupval, eq, len);
@@ -1152,12 +1148,10 @@ static int handle_section(struct parser_obj *po, uint32_t *action)
}
/* Dup the name */
- errno = 0;
dupval = malloc(len + 1);
if (!dupval) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to dup section name", error);
- return error;
+ TRACE_ERROR_NUMBER("Failed to dup section name", ENOMEM);
+ return ENOMEM;
}
memcpy(dupval, start, len);