loadparm: Add convenience function to return long integers
authorSimo Sorce <idra@samba.org>
Thu, 19 Apr 2012 15:00:45 +0000 (11:00 -0400)
committerSimo Sorce <idra@samba.org>
Thu, 19 Apr 2012 22:14:02 +0000 (18:14 -0400)
lib/param/loadparm.c

index 3ccf4668fcab9e219af390b21caca7fe24c3031f..d68d585617115b70d0615364f3550e8cd53701ea 100644 (file)
@@ -1710,6 +1710,20 @@ static unsigned long lp_ulong(const char *s)
        return strtoul(s, NULL, 0);
 }
 
+/**
+ * convenience routine to return unsigned long parameters.
+ */
+static long lp_long(const char *s)
+{
+
+       if (!s) {
+               DEBUG(0,("lp_long(%s): is called with NULL!\n",s));
+               return -1;
+       }
+
+       return strtol(s, NULL, 0);
+}
+
 /**
  * convenience routine to return unsigned long parameters.
  */
@@ -1840,6 +1854,17 @@ unsigned long lpcfg_parm_ulong(struct loadparm_context *lp_ctx,
        return default_v;
 }
 
+long lpcfg_parm_long(struct loadparm_context *lp_ctx,
+                    struct loadparm_service *service, const char *type,
+                    const char *option, long default_v)
+{
+       const char *value = lpcfg_get_parametric(lp_ctx, service, type, option);
+
+       if (value)
+               return lp_long(value);
+
+       return default_v;
+}
 
 double lpcfg_parm_double(struct loadparm_context *lp_ctx,
                      struct loadparm_service *service, const char *type,