]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/getenv_num.c
ncurses 5.9 - patch 20130713
[ncurses.git] / ncurses / tinfo / getenv_num.c
index 62944048175ac90024ba7dba1b6d056d372b9e4b..62f3d4d4ca8b3b391ca08bb431e6c2acbe461dcd 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1998-2000,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 
 #include <curses.priv.h>
 
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: getenv_num.c,v 1.1 1998/09/19 21:30:23 tom Exp $")
+MODULE_ID("$Id: getenv_num.c,v 1.4 2012/07/14 21:17:19 tom Exp $")
 
 
-int
+NCURSES_EXPORT(int)
 _nc_getenv_num(const char *name)
 {
 _nc_getenv_num(const char *name)
 {
-       char *dst = 0;
-       char *src = getenv(name);
-       long value;
-
-       if ((src == 0)
-        || (value = strtol(src, &dst, 0)) < 0
-        || (dst == src)
-        || (*dst != '\0')
-        || (int)value < value)
-               value = -1;
-
-       return (int) value;
+    char *dst = 0;
+    char *src = getenv(name);
+    long value;
+
+    if ((src == 0)
+       || (value = strtol(src, &dst, 0)) < 0
+       || (dst == src)
+       || (*dst != '\0')
+       || (int) value < value)
+       value = -1;
+
+    return (int) value;
+}
+
+NCURSES_EXPORT(void)
+_nc_setenv_num(const char *name, int value)
+{
+    if (name != 0 && value >= 0) {
+       char buffer[128];
+#if HAVE_SETENV
+       sprintf(buffer, "%d", value);
+       setenv(name, buffer, 1);
+#elif HAVE_PUTENV
+       char *s;
+       sprintf(buffer, "%s=%d", name, value);
+       if ((s = strdup(buffer)) != 0)
+           putenv(s);
+#endif
+    }
 }
 }