ncurses 6.0 - patch 20170114
[ncurses.git] / ncurses / tinfo / home_terminfo.c
index fac19bf52418a8cb7bbdc44111362628ebbe7fec..5c2869d4800f5797ed1062c5361a96ff955bd41f 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2002,2004 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2016 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            *
@@ -27,7 +27,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey 1998,2000,2004                                 *
+ *  Author: Thomas E. Dickey                                                *
  ****************************************************************************/
 
 /*
 #include <curses.priv.h>
 #include <tic.h>
 
-MODULE_ID("$Id: home_terminfo.c,v 1.8 2004/01/14 02:18:16 tom Exp $")
-
-#define my_length (strlen(home) + sizeof(PRIVATE_INFO))
+MODULE_ID("$Id: home_terminfo.c,v 1.16 2016/05/28 23:22:52 tom Exp $")
 
 /* ncurses extension...fall back on user's private directory */
 
+#define MyBuffer _nc_globals.home_terminfo
+
 NCURSES_EXPORT(char *)
 _nc_home_terminfo(void)
 {
-#ifdef USE_HOME_TERMINFO
-    char *home;
-    static char *temp = 0;
-
+    char *result = 0;
+#if USE_HOME_TERMINFO
     if (use_terminfo_vars()) {
-       if (temp == 0) {
-           if ((home = getenv("HOME")) != 0
-               && my_length <= PATH_MAX) {
-               temp = typeMalloc(char, my_length);
-               if (temp == 0)
-                   _nc_err_abort(MSG_NO_MEMORY);
-               (void) sprintf(temp, PRIVATE_INFO, home);
+
+       if (MyBuffer == 0) {
+           char *home;
+
+           if ((home = getenv("HOME")) != 0) {
+               size_t want = (strlen(home) + sizeof(PRIVATE_INFO));
+               TYPE_MALLOC(char, want, MyBuffer);
+               _nc_SPRINTF(MyBuffer, _nc_SLIMIT(want) PRIVATE_INFO, home);
            }
        }
-       return temp;
+       result = MyBuffer;
     }
 #endif
-    return 0;
+    return result;
 }