* lib/sgroupio.c: Avoid assignments in comparisons.

* lib/sgroupio.c: Add brackets.
	* lib/sgroupio.c: Avoid implicit conversion of pointers / integers to booleans.
	* lib/sgroupio.c: The changed, isopen, locked, and readonly fields of the db are booleans.
	* lib/sgroupio.h, lib/sgroupio.c: sgr_file_present returns a bool.
	* lib/sgroupio.h: Add protection against multiple inclusions.
This commit is contained in:
nekral-guest 2008-05-26 08:46:41 +00:00
parent 77020623ed
commit caed1add3a

View File

@ -47,33 +47,43 @@ struct sgrp *__sgr_dup (const struct sgrp *sgent)
struct sgrp *sg; struct sgrp *sg;
int i; int i;
if (!(sg = (struct sgrp *) malloc (sizeof *sg))) sg = (struct sgrp *) malloc (sizeof *sg);
if (NULL == sg) {
return NULL; return NULL;
}
*sg = *sgent; *sg = *sgent;
if (!(sg->sg_name = strdup (sgent->sg_name))) sg->sg_name = strdup (sgent->sg_name);
if (NULL == sg->sg_name) {
return NULL; return NULL;
if (!(sg->sg_passwd = strdup (sgent->sg_passwd))) }
sg->sg_passwd = strdup (sgent->sg_passwd);
if (NULL == sg->sg_passwd) {
return NULL; return NULL;
}
for (i = 0; sgent->sg_adm[i]; i++); for (i = 0; NULL != sgent->sg_adm[i]; i++);
sg->sg_adm = (char **) malloc ((i + 1) * sizeof (char *)); sg->sg_adm = (char **) malloc ((i + 1) * sizeof (char *));
if (!sg->sg_adm) if (NULL == sg->sg_adm) {
return NULL; return NULL;
for (i = 0; sgent->sg_adm[i]; i++) { }
for (i = 0; NULL != sgent->sg_adm[i]; i++) {
sg->sg_adm[i] = strdup (sgent->sg_adm[i]); sg->sg_adm[i] = strdup (sgent->sg_adm[i]);
if (!sg->sg_adm[i]) if (NULL == sg->sg_adm[i]) {
return NULL; return NULL;
}
} }
sg->sg_adm[i] = NULL; sg->sg_adm[i] = NULL;
for (i = 0; sgent->sg_mem[i]; i++); for (i = 0; NULL != sgent->sg_mem[i]; i++);
sg->sg_mem = (char **) malloc ((i + 1) * sizeof (char *)); sg->sg_mem = (char **) malloc ((i + 1) * sizeof (char *));
if (!sg->sg_mem) if (NULL == sg->sg_mem) {
return NULL; return NULL;
for (i = 0; sgent->sg_mem[i]; i++) { }
for (i = 0; NULL != sgent->sg_mem[i]; i++) {
sg->sg_mem[i] = strdup (sgent->sg_mem[i]); sg->sg_mem[i] = strdup (sgent->sg_mem[i]);
if (!sg->sg_mem[i]) if (NULL == sg->sg_mem[i]) {
return NULL; return NULL;
}
} }
sg->sg_mem[i] = NULL; sg->sg_mem[i] = NULL;
@ -93,11 +103,11 @@ static void gshadow_free (void *ent)
free (sg->sg_name); free (sg->sg_name);
free (sg->sg_passwd); free (sg->sg_passwd);
while (*(sg->sg_adm)) { while (NULL != *(sg->sg_adm)) {
free (*(sg->sg_adm)); free (*(sg->sg_adm));
sg->sg_adm++; sg->sg_adm++;
} }
while (*(sg->sg_mem)) { while (NULL != *(sg->sg_mem)) {
free (*(sg->sg_mem)); free (*(sg->sg_mem));
sg->sg_mem++; sg->sg_mem++;
} }
@ -145,10 +155,10 @@ static struct commonio_db gshadow_db = {
NULL, /* head */ NULL, /* head */
NULL, /* tail */ NULL, /* tail */
NULL, /* cursor */ NULL, /* cursor */
0, /* changed */ false, /* changed */
0, /* isopen */ false, /* isopen */
0, /* locked */ false, /* locked */
0 /* readonly */ false /* readonly */
}; };
int sgr_name (const char *filename) int sgr_name (const char *filename)
@ -156,7 +166,7 @@ int sgr_name (const char *filename)
return commonio_setname (&gshadow_db, filename); return commonio_setname (&gshadow_db, filename);
} }
int sgr_file_present (void) bool sgr_file_present (void)
{ {
return commonio_present (&gshadow_db); return commonio_present (&gshadow_db);
} }
@ -208,7 +218,7 @@ int sgr_unlock (void)
void __sgr_set_changed (void) void __sgr_set_changed (void)
{ {
gshadow_db.changed = 1; gshadow_db.changed = true;
} }
struct commonio_entry *__sgr_get_head (void) struct commonio_entry *__sgr_get_head (void)