* lib/getdef.c: Added splint annotations.

* lib/getdef.c: Ignore fputs() return value.
	* lib/getdef.c: Use EXIT_FAILURE / EXIT_SUCCESS for exit()
This commit is contained in:
nekral-guest 2009-04-23 11:46:46 +00:00
parent 0c6159650d
commit 43033b65ad

View File

@ -45,8 +45,8 @@
* A configuration item definition. * A configuration item definition.
*/ */
struct itemdef { struct itemdef {
const char *name; /* name of the item */ /*@null@*/const char *name; /* name of the item */
char *value; /* value given, or NULL if no value */ /*@null@*/char *value; /* value given, or NULL if no value */
}; };
#define NUMDEFS (sizeof(def_table)/sizeof(def_table[0])) #define NUMDEFS (sizeof(def_table)/sizeof(def_table[0]))
@ -135,7 +135,7 @@ static char def_fname[] = LOGINDEFS; /* login config defs file */
static bool def_loaded = false; /* are defs already loaded? */ static bool def_loaded = false; /* are defs already loaded? */
/* local function prototypes */ /* local function prototypes */
static struct itemdef *def_find (const char *); static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *);
static void def_load (void); static void def_load (void);
@ -146,7 +146,7 @@ static void def_load (void);
* defined. First time invoked, will load definitions from the file. * defined. First time invoked, will load definitions from the file.
*/ */
char *getdef_str (const char *item) /*@observer@*/ /*@null@*/const char *getdef_str (const char *item)
{ {
struct itemdef *d; struct itemdef *d;
@ -155,7 +155,7 @@ char *getdef_str (const char *item)
} }
d = def_find (item); d = def_find (item);
return ((NULL == d)? (char *) NULL : d->value); return ((NULL == d)? (const char *) NULL : d->value);
} }
@ -295,7 +295,7 @@ long getdef_long (const char *item, long dflt)
unsigned long getdef_ulong (const char *item, unsigned long dflt) unsigned long getdef_ulong (const char *item, unsigned long dflt)
{ {
struct itemdef *d; struct itemdef *d;
long val; unsigned long val;
if (!def_loaded) { if (!def_loaded) {
def_load (); def_load ();
@ -306,7 +306,7 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
return dflt; return dflt;
} }
if (getlong (d->value, &val) == 0) { if (getulong (d->value, &val) == 0) {
/* FIXME: we should have a getulong */ /* FIXME: we should have a getulong */
fprintf (stderr, fprintf (stderr,
_("configuration error - cannot parse %s value: '%s'"), _("configuration error - cannot parse %s value: '%s'"),
@ -345,8 +345,8 @@ int putdef_str (const char *name, const char *value)
*/ */
cp = strdup (value); cp = strdup (value);
if (NULL == cp) { if (NULL == cp) {
fputs (_("Could not allocate space for config info.\n"), (void) fputs (_("Could not allocate space for config info.\n"),
stderr); stderr);
SYSLOG ((LOG_ERR, "could not allocate space for config info")); SYSLOG ((LOG_ERR, "could not allocate space for config info"));
return -1; return -1;
} }
@ -367,7 +367,7 @@ int putdef_str (const char *name, const char *value)
* specified configuration option. * specified configuration option.
*/ */
static struct itemdef *def_find (const char *name) static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
{ {
struct itemdef *ptr; struct itemdef *ptr;
@ -413,7 +413,7 @@ static void def_load (void)
int err = errno; int err = errno;
SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%s]", SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%s]",
def_fname, strerror (err))); def_fname, strerror (err)));
exit (1); exit (EXIT_FAILURE);
} }
/* /*
@ -455,15 +455,19 @@ static void def_load (void)
/* /*
* Store the value in def_table. * Store the value in def_table.
*
* Ignore failures to load the login.defs file.
* The error was already reported to the user and to
* syslog. The tools will just use their default values.
*/ */
putdef_str (name, value); (void)putdef_str (name, value);
} }
if (ferror (fp) != 0) { if (ferror (fp) != 0) {
int err = errno; int err = errno;
SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%s]", SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%s]",
def_fname, strerror (err))); def_fname, strerror (err)));
exit (1); exit (EXIT_FAILURE);
} }
(void) fclose (fp); (void) fclose (fp);
@ -496,6 +500,6 @@ int main (int argc, char **argv)
printf ("%s not found\n", argv[1]); printf ("%s not found\n", argv[1]);
} }
} }
exit (0); exit (EXIT_SUCCESS);
} }
#endif #endif