tweaks: reduce the scope of two constants and of four variables
parent
8455251c35
commit
6896d8df47
18
src/files.c
18
src/files.c
|
@ -30,7 +30,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef NANO_TINY
|
||||||
#define LOCKBUFSIZE 8192
|
#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. */
|
/* Verify that the containing directory of the given filename exists. */
|
||||||
bool has_valid_path(const char *filename)
|
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 *namecopy = copy_of(filename);
|
||||||
char *secondcopy = copy_of(filename);
|
char *secondcopy = copy_of(filename);
|
||||||
size_t locknamesize = strlen(filename) + strlen(locking_prefix)
|
size_t locknamesize = strlen(filename) + strlen(locking_prefix) +
|
||||||
+ strlen(locking_suffix) + 3;
|
strlen(locking_suffix) + 3;
|
||||||
char *lockfilename = charalloc(locknamesize);
|
char *lockfilename = charalloc(locknamesize);
|
||||||
static char lockprog[11], lockuser[17];
|
|
||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
int lockfd, lockpid, retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
snprintf(lockfilename, locknamesize, "%s/%s%s%s", dirname(namecopy),
|
snprintf(lockfilename, locknamesize, "%s/%s%s%s", dirname(namecopy),
|
||||||
locking_prefix, basename(secondcopy), locking_suffix);
|
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)
|
if (!ask_the_user && stat(lockfilename, &fileinfo) != -1)
|
||||||
warn_and_shortly_pause(_("Someone else is also editing this file"));
|
warn_and_shortly_pause(_("Someone else is also editing this file"));
|
||||||
else if (stat(lockfilename, &fileinfo) != -1) {
|
else if (stat(lockfilename, &fileinfo) != -1) {
|
||||||
size_t readtot = 0;
|
|
||||||
size_t readamt = 0;
|
|
||||||
char *lockbuf, *question, *pidstring, *postedname, *promptstr;
|
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) {
|
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
|
||||||
statusline(MILD, _("Error opening lock file %s: %s"),
|
statusline(MILD, _("Error opening lock file %s: %s"),
|
||||||
|
|
|
@ -171,11 +171,6 @@ ssize_t tabsize = -1;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
char *backup_dir = NULL;
|
char *backup_dir = NULL;
|
||||||
/* The directory where we store backup files. */
|
/* 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
|
#endif
|
||||||
#ifdef ENABLE_OPERATINGDIR
|
#ifdef ENABLE_OPERATINGDIR
|
||||||
char *operating_dir = NULL;
|
char *operating_dir = NULL;
|
||||||
|
|
|
@ -127,8 +127,6 @@ extern ssize_t tabsize;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
extern char *backup_dir;
|
extern char *backup_dir;
|
||||||
extern const char *locking_prefix;
|
|
||||||
extern const char *locking_suffix;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_OPERATINGDIR
|
#ifdef ENABLE_OPERATINGDIR
|
||||||
extern char *operating_dir;
|
extern char *operating_dir;
|
||||||
|
|
Loading…
Reference in New Issue