aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-12-13 02:41:30 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-12-13 02:41:30 +0530
commitc3545dd82f37fb7ef803a699765e6c0ba42c2bad (patch)
tree51dde308d13eb9d2709eb14e7d9b9a08eef764c2
parent5ae9993a12ffdc190241ec41db60e48e452f22be (diff)
downloadnnn-c3545dd82f37fb7ef803a699765e6c0ba42c2bad.tar.gz
Use static vars in frequently used APIs
-rw-r--r--nnn.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/nnn.c b/nnn.c
index 5614d07..e7ab8ec 100644
--- a/nnn.c
+++ b/nnn.c
@@ -450,7 +450,8 @@ static char *
xdirname(const char *path)
{
static char *buf = g_buf;
- static char *last_slash;
+ static char *last_slash, *runp;
+
xstrlcpy(buf, path, PATH_MAX);
@@ -459,8 +460,6 @@ xdirname(const char *path)
if (last_slash != NULL && last_slash != buf && last_slash[1] == '\0') {
/* Determine whether all remaining characters are slashes. */
- char *runp;
-
for (runp = last_slash; runp != buf; --runp)
if (runp[-1] != '/')
break;
@@ -472,8 +471,6 @@ xdirname(const char *path)
if (last_slash != NULL) {
/* Determine whether all remaining characters are slashes. */
- char *runp;
-
for (runp = last_slash; runp != buf; --runp)
if (runp[-1] != '/')
break;
@@ -609,10 +606,12 @@ spawn(char *file, char *arg1, char *arg2, char *dir, uchar flag)
static char *
xgetenv(char *name, char *fallback)
{
+ static char *value;
+
if (name == NULL)
return fallback;
- char *value = getenv(name);
+ value = getenv(name);
return value && value[0] ? value : fallback;
}
@@ -726,8 +725,8 @@ strstrip(char *s)
static char *
getmime(char *file)
{
- regex_t regex;
- uint i;
+ static regex_t regex;
+ static uint i;
static uint len = LEN(assocs);
for (i = 0; i < len; ++i) {