openfile->totsize = 0;
}
-
#ifndef NANO_TINY
-/* Actyally write the lock file. This function will
- ALWAYS annihilate any previous version of the file.
- We'll borrow INSECURE_BACKUP here to decide about lock file
- paranoia here as well...
- Args:
- lockfilename: file name for lock
- origfilename: name of the file the lock is for
- modified: whether to set the modified bit in the file
-
- Returns: 1 on success, 0 on failure (but continue loading), -1 on failure and abort
- */
+/* Actually write the lockfile. This function will ALWAYS annihilate
+ * any previous version of the file. We'll borrow INSECURE_BACKUP here
+ * to decide about lockfile paranoia here as well...
+ *
+ * Args:
+ * lockfilename: file name for lock
+ * origfilename: name of the file the lock is for
+ * modified: whether to set the modified bit in the file
+ *
+ * Returns: 1 on success, 0 on failure (but continue loading), -1 on
+ * failure and abort. */
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
{
int cflags, fd;
ssize_t lockdatalen = 1024;
ssize_t wroteamt;
- /* Run things which might fail first before we try and blow away
- the old state */
+ /* Run things which might fail first before we try and blow away the
+ * old state. */
myuid = geteuid();
if ((mypwuid = getpwuid(myuid)) == NULL) {
statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)"));
fd = open(lockfilename, cflags,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
- /* Maybe we just don't have write access, don't stop us from
- opening the file at all, just don't set the lock_filename
- and return success */
+ /* Maybe we just don't have write access. Don't stop us from
+ * opening the file at all, just don't set the lock_filename and
+ * return success. */
if (fd < 0 && errno == EACCES)
return 1;
- /* Now we've got a safe file stream. If the previous open()
- call failed, this will return NULL. */
+ /* Now we've got a safe file stream. If the previous open() call
+ * failed, this will return NULL. */
filestream = fdopen(fd, "wb");
if (fd < 0 || filestream == NULL) {
return -1;
}
-
- /* Okay. so at the moment we're following this state for how
- to store the lock data:
- byte 0 - 0x62
- byte 1 - 0x30
- bytes 2-12 - program name which created the lock
- bytes 24,25 - little endian store of creator program's PID
- (b24 = 256^0 column, b25 = 256^1 column)
- bytes 28-44 - username of who created the lock
- bytes 68-100 - hostname of where the lock was created
- bytes 108-876 - filename the lock is for
- byte 1007 - 0x55 if file is modified
-
- Looks like VIM also stores undo state in this file so we're
- gonna have to figure out how to slap a 'OMG don't use recover
- on our lockfile' message in here...
-
- This is likely very wrong, so this is a WIP
- */
+ /* Okay, so at the moment we're following this state for how to
+ * store the lock data:
+ *
+ * byte 0 - 0x62
+ * byte 1 - 0x30
+ * bytes 2-12 - program name which created the lock
+ * bytes 24,25 - little endian store of creator program's PID
+ * (b24 = 256^0 column, b25 = 256^1 column)
+ * bytes 28-44 - username of who created the lock
+ * bytes 68-100 - hostname of where the lock was created
+ * bytes 108-876 - filename the lock is for
+ * byte 1007 - 0x55 if file is modified
+ *
+ * Looks like VIM also stores undo state in this file, so we're
+ * gonna have to figure out how to slap a 'OMG don't use recover on
+ * our lockfile' message in here...
+ *
+ * This is likely very wrong, so this is a WIP. */
null_at(&lockdata, lockdatalen);
lockdata[0] = 0x62;
lockdata[1] = 0x30;
return 1;
}
-
-/* Less exciting, delete the lock file.
- Return -1 if successful and complain on the statusbar, 1 otherwite
- */
+/* Less exciting, delete the lockfile. Return -1 if unsuccessful and
+ * complain on the statusbar, 1 otherwise. */
int delete_lockfile(const char *lockfilename)
{
if (unlink(lockfilename) < 0 && errno != ENOENT) {
return 1;
}
-
-/* Deal with lockfiles. Return -1 on refusing to override
- the lock file, and 1 on successfully created the lockfile, 0 means
- we were not successful on creating the lockfile but we should
- continue to load the file and complain to the user.
- */
+/* Deal with lockfiles. Return -1 on refusing to override the lockfile,
+ * and 1 on successfully creating it; 0 means we were not successful in
+ * creating the lockfile but we should continue to load the file and
+ * complain to the user. */
int do_lockfile(const char *filename)
{
char *lockdir = dirname((char *) mallocstrcpy(NULL, filename));
struct stat fileinfo;
int lockfd, lockpid;
-
snprintf(lockfilename, lockfilesize, "%s/%s%s%s", lockdir,
locking_prefix, lockbase, locking_suffix);
#ifdef DEBUG
}
#endif /* !NANO_TINY */
-
/* If it's not "", filename is a file to open. We make a new buffer, if
* necessary, and then open and read the file, if applicable. */
void open_buffer(const char *filename, bool undoable)
}
#endif /* !DISABLE_MULTIBUFFER */
-/* A bit of a copy and paste from open_file(), is_file_writable()
- * just checks whether the file is appendable as a quick
- * permissions check, and we tend to err on the side of permissiveness
- * (reporting TRUE when it might be wrong) to not fluster users
- * editing on odd filesystems by printing incorrect warnings.
- */
+/* A bit of a copy and paste from open_file(), is_file_writable() just
+ * checks whether the file is appendable as a quick permissions check,
+ * and we tend to err on the side of permissiveness (reporting TRUE when
+ * it might be wrong) to not fluster users editing on odd filesystems by
+ * printing incorrect warnings. */
int is_file_writable(const char *filename)
{
struct stat fileinfo, fileinfo2;
/* Read an open file into the current buffer. f should be set to the
* open file, and filename should be set to the name of the file.
- * undoable means do we want to create undo records to try and undo this.
- * Will also attempt to check file writability if fd > 0 and checkwritable == TRUE
- */
+ * undoable means do we want to create undo records to try and undo
+ * this. Will also attempt to check file writability if fd > 0 and
+ * checkwritable == TRUE. */
void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkwritable)
{
size_t num_lines = 0;
#endif
if (stat(full_filename, &fileinfo) == -1) {
- /* Well, maybe we can open the file even if the OS
- says its not there */
+ /* Well, maybe we can open the file even if the OS says it's
+ * not there. */
if ((fd = open(filename, O_RDONLY)) != -1) {
statusbar(_("Reading File"));
free(full_filename);
#endif
#ifndef NANO_TINY
-/* Although this sucks, it sucks less than having a single 'my system is messed up
- * and I'm blanket allowing insecure file writing operations.
- */
-
+/* Although this sucks, it sucks less than having a single 'my system is
+ * messed up and I'm blanket allowing insecure file writing operations'. */
int prompt_failed_backupwrite(const char *filename)
{
static int i;
- static char *prevfile = NULL; /* What was the laast file we were paased so we don't keep asking this?
- though maybe we should.... */
+ static char *prevfile = NULL; /* What was the last file we were
+ * passed so we don't keep asking
+ * this? Though maybe we should... */
if (prevfile == NULL || strcmp(filename, prevfile)) {
i = do_yesno_prompt(FALSE,
_("Failed to write backup file, continue saving? (Say N if unsure) "));
return construct_filename("/.nano/search_history");
}
-/* Construct the legacy history filename
- * (Deprecate in 2.5, delete later
- */
+/* Construct the legacy history filename.
+ * (Deprecate in 2.5, delete later.) */
char *legacyhistfilename(void)
{
return construct_filename("/.nano_history");
}
-/* Now that we have more than one history file, let's just rely
- on a .nano dir for this stuff. Return 1 if the dir exists
- or was successfully created, and return 0 otherwise.
- */
+/* Now that we have more than one history file, let's just rely on a
+ * .nano dir for this stuff. Return 1 if the dir exists or was
+ * successfully created, and return 0 otherwise. */
int check_dotnano(void)
{
struct stat dirstat;
}
}
-
-/* Analogs for the POS history */
+/* Analogs for the POS history. */
void save_poshistory(void)
{
char *poshist;
}
}
-/* Update the POS history, given a filename line and column.
- * If no entry is found, add a new entry on the end
- */
+/* Update the POS history, given a filename line and column. If no
+ * entry is found, add a new entry on the end. */
void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos)
{
poshiststruct *posptr, *posprev = NULL;
}
-/* Check the POS history to see if file matches
- * an existing entry. If so return 1 and set line and column
- * to the right values Otherwise return 0
- */
+/* Check the POS history to see if file matches an existing entry. If
+ * so, return 1 and set line and column to the right values. Otherwise,
+ * return 0. */
int check_poshistory(const char *file, ssize_t *line, ssize_t *column)
{
poshiststruct *posptr;