+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>
* src/id.c: Make sure malloc receives a size_t.
}
return (int) strtol (d->value, (char **) NULL, 0);
+ /* TODO: check for errors */
}
}
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
+ /* TODO: check for errors */
}
}
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
/*
* 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.
*/
- for (i = strlen (buf) - 1; i >= 0; --i) {
+ for (i = (int) strlen (buf) - 1; i >= 0; --i) {
if (!isspace (buf[i])) {
break;
}
}
- buf[++i] = '\0';
+ i++;
+ buf[i] = '\0';
/*
* Break the line into two fields.
extern bool getdef_bool (const char *);
extern long getdef_long (const char *, long);
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 char *getdef_str (const char *);
extern int putdef_str (const char *, const char *);