* lib/getdef.h, lib/getdef.c: Add getdef_ulong().
* lib/getdef.c: Added TODOs because of lack of error checking. * lib/getdef.c: The size argument of fgets is an int, not a size_t. * lib/getdef.c: Avoid multi-statements lines.
This commit is contained in:
parent
5fc99a117b
commit
c9679b7954
@ -1,3 +1,11 @@
|
|||||||
|
2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* lib/getdef.h, lib/getdef.c: Add getdef_ulong().
|
||||||
|
* lib/getdef.c: Added TODOs because of lack of error checking.
|
||||||
|
* lib/getdef.c: The size argument of fgets is an int, not a
|
||||||
|
size_t.
|
||||||
|
* lib/getdef.c: Avoid multi-statements lines.
|
||||||
|
|
||||||
2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
|
2008-06-13 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* src/id.c: Make sure malloc receives a size_t.
|
* src/id.c: Make sure malloc receives a size_t.
|
||||||
|
34
lib/getdef.c
34
lib/getdef.c
@ -203,6 +203,7 @@ int getdef_num (const char *item, int dflt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (int) strtol (d->value, (char **) NULL, 0);
|
return (int) strtol (d->value, (char **) NULL, 0);
|
||||||
|
/* TODO: check for errors */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -228,6 +229,7 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
|
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
|
||||||
|
/* TODO: check for errors */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -253,8 +255,33 @@ long getdef_long (const char *item, long dflt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return strtol (d->value, (char **) NULL, 0);
|
return strtol (d->value, (char **) NULL, 0);
|
||||||
|
/* TODO: check for errors */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getdef_ulong - get unsigned long numerical value from table of definitions
|
||||||
|
*
|
||||||
|
* Returns numeric value of specified item, else the "dflt" value if
|
||||||
|
* the item is not defined. Octal (leading "0") and hex (leading "0x")
|
||||||
|
* values are handled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned long getdef_ulong (const char *item, unsigned int dflt)
|
||||||
|
{
|
||||||
|
struct itemdef *d;
|
||||||
|
|
||||||
|
if (!def_loaded) {
|
||||||
|
def_load ();
|
||||||
|
}
|
||||||
|
|
||||||
|
d = def_find (item);
|
||||||
|
if ((NULL == d) || (NULL == d->value)) {
|
||||||
|
return dflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (unsigned long) strtoul (d->value, (char **) NULL, 0);
|
||||||
|
/* TODO: check for errors */
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* putdef_str - override the value read from /etc/login.defs
|
* putdef_str - override the value read from /etc/login.defs
|
||||||
@ -364,17 +391,18 @@ static void def_load (void)
|
|||||||
/*
|
/*
|
||||||
* Go through all of the lines in the file.
|
* Go through all of the lines in the file.
|
||||||
*/
|
*/
|
||||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
while (fgets (buf, (int) sizeof (buf), fp) != NULL) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Trim trailing whitespace.
|
* Trim trailing whitespace.
|
||||||
*/
|
*/
|
||||||
for (i = strlen (buf) - 1; i >= 0; --i) {
|
for (i = (int) strlen (buf) - 1; i >= 0; --i) {
|
||||||
if (!isspace (buf[i])) {
|
if (!isspace (buf[i])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[++i] = '\0';
|
i++;
|
||||||
|
buf[i] = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Break the line into two fields.
|
* Break the line into two fields.
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
extern bool getdef_bool (const char *);
|
extern bool getdef_bool (const char *);
|
||||||
extern long getdef_long (const char *, long);
|
extern long getdef_long (const char *, long);
|
||||||
extern int getdef_num (const char *, int);
|
extern int getdef_num (const char *, int);
|
||||||
|
extern unsigned int getdef_ulong (const char *, unsigned long);
|
||||||
extern unsigned int getdef_unum (const char *, unsigned int);
|
extern unsigned int getdef_unum (const char *, unsigned int);
|
||||||
extern char *getdef_str (const char *);
|
extern char *getdef_str (const char *);
|
||||||
extern int putdef_str (const char *, const char *);
|
extern int putdef_str (const char *, const char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user