tweaks: reduce the scope of two constants and of four variables

master
Benno Schulenberg 2020-01-14 10:35:54 +01:00
parent 8455251c35
commit 6896d8df47
3 changed files with 11 additions and 14 deletions

View File

@ -30,7 +30,12 @@
#include <string.h>
#include <unistd.h>
#ifndef NANO_TINY
#define LOCKBUFSIZE 8192
const char *locking_prefix = ".";
const char *locking_suffix = ".swp";
/* Prefix and suffix for the name of the vim-style lock file. */
#endif
/* Verify that the containing directory of the given filename exists. */
bool has_valid_path(const char *filename)
@ -295,12 +300,11 @@ int do_lockfile(const char *filename, bool ask_the_user)
{
char *namecopy = copy_of(filename);
char *secondcopy = copy_of(filename);
size_t locknamesize = strlen(filename) + strlen(locking_prefix)
+ strlen(locking_suffix) + 3;
size_t locknamesize = strlen(filename) + strlen(locking_prefix) +
strlen(locking_suffix) + 3;
char *lockfilename = charalloc(locknamesize);
static char lockprog[11], lockuser[17];
struct stat fileinfo;
int lockfd, lockpid, retval = -1;
int retval = -1;
snprintf(lockfilename, locknamesize, "%s/%s%s%s", dirname(namecopy),
locking_prefix, basename(secondcopy), locking_suffix);
@ -308,10 +312,10 @@ int do_lockfile(const char *filename, bool ask_the_user)
if (!ask_the_user && stat(lockfilename, &fileinfo) != -1)
warn_and_shortly_pause(_("Someone else is also editing this file"));
else if (stat(lockfilename, &fileinfo) != -1) {
size_t readtot = 0;
size_t readamt = 0;
char *lockbuf, *question, *pidstring, *postedname, *promptstr;
int room, choice;
static char lockprog[11], lockuser[17];
int lockfd, lockpid, room, choice;
size_t readamt = 0, readtot = 0;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
statusline(MILD, _("Error opening lock file %s: %s"),

View File

@ -171,11 +171,6 @@ ssize_t tabsize = -1;
#ifndef NANO_TINY
char *backup_dir = NULL;
/* The directory where we store backup files. */
const char *locking_prefix = ".";
/* Prefix of how to store the vim-style lock file. */
const char *locking_suffix = ".swp";
/* Suffix of the vim-style lock file. */
#endif
#ifdef ENABLE_OPERATINGDIR
char *operating_dir = NULL;

View File

@ -127,8 +127,6 @@ extern ssize_t tabsize;
#ifndef NANO_TINY
extern char *backup_dir;
extern const char *locking_prefix;
extern const char *locking_suffix;
#endif
#ifdef ENABLE_OPERATINGDIR
extern char *operating_dir;