* old state. */
myuid = geteuid();
if ((mypwuid = getpwuid(myuid)) == NULL) {
- statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)"));
- return -1;
+ statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)"));
+ return -1;
}
mypid = getpid();
if (gethostname(myhostname, 31) < 0) {
- statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno));
- return -1;
+ statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno));
+ return -1;
}
/* Check if the lock exists before we try to delete it...*/
return -1;
if (ISSET(INSECURE_BACKUP))
- cflags = O_WRONLY | O_CREAT | O_APPEND;
+ cflags = O_WRONLY | O_CREAT | O_APPEND;
else
- cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND;
+ cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND;
fd = open(lockfilename, cflags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
/* Maybe we just don't have write access. Print an error message
- and continue. */
+ * and continue. */
if (fd < 0) {
- statusbar(_("Error writing lock file %s: %s"), lockfilename,
+ statusbar(_("Error writing lock file %s: %s"), lockfilename,
strerror(errno));
- return 0;
+ return 0;
}
/* Now we've got a safe file stream. If the previous open() call
filestream = fdopen(fd, "wb");
if (fd < 0 || filestream == NULL) {
- statusbar(_("Error writing lock file %s: %s"), lockfilename,
+ statusbar(_("Error writing lock file %s: %s"), lockfilename,
strerror(errno));
- return -1;
+ return -1;
}
/* Okay, so at the moment we're following this state for how to
strncpy(&lockdata[68], myhostname, 31);
strncpy(&lockdata[108], origfilename, 768);
if (modified == TRUE)
- lockdata[1007] = 0x55;
+ lockdata[1007] = 0x55;
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
if (wroteamt < lockdatalen) {
- statusbar(_("Error writing lock file %s: %s"),
- lockfilename, ferror(filestream));
- return -1;
+ statusbar(_("Error writing lock file %s: %s"),
+ lockfilename, ferror(filestream));
+ return -1;
}
#ifdef DEBUG
#endif
if (fclose(filestream) == EOF) {
- statusbar(_("Error writing lock file %s: %s"),
- lockfilename, strerror(errno));
- return -1;
+ statusbar(_("Error writing lock file %s: %s"),
+ lockfilename, strerror(errno));
+ return -1;
}
openfile->lock_filename = lockfilename;
if (unlink(lockfilename) < 0 && errno != ENOENT) {
statusbar(_("Error deleting lock file %s: %s"), lockfilename,
strerror(errno));
- return -1;
+ return -1;
}
return 1;
}
int lockfd, lockpid;
snprintf(lockfilename, lockfilesize, "%s/%s%s%s", lockdir,
- locking_prefix, lockbase, locking_suffix);
+ locking_prefix, lockbase, locking_suffix);
#ifdef DEBUG
fprintf(stderr, "lock file name is %s\n", lockfilename);
#endif
if (stat(lockfilename, &fileinfo) != -1) {
- ssize_t readtot = 0;
- ssize_t readamt = 0;
- char *lockbuf = charalloc(8192);
- char *promptstr = charalloc(128);
- int ans;
- if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
- statusbar(_("Error opening lock file %s: %s"),
- lockfilename, strerror(errno));
- return -1;
- }
- do {
- readamt = read(lockfd, &lockbuf[readtot], BUFSIZ);
- readtot += readamt;
- } while (readtot < 8192 && readamt > 0);
-
- if (readtot < 48) {
- statusbar(_("Error reading lock file %s: Not enough data read"),
- lockfilename);
- return -1;
- }
- strncpy(lockprog, &lockbuf[2], 10);
- lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24];
- strncpy(lockuser, &lockbuf[28], 16);
+ ssize_t readtot = 0;
+ ssize_t readamt = 0;
+ char *lockbuf = charalloc(8192);
+ char *promptstr = charalloc(128);
+ int ans;
+ if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
+ statusbar(_("Error opening lock file %s: %s"),
+ lockfilename, strerror(errno));
+ return -1;
+ }
+ do {
+ readamt = read(lockfd, &lockbuf[readtot], BUFSIZ);
+ readtot += readamt;
+ } while (readtot < 8192 && readamt > 0);
+
+ if (readtot < 48) {
+ statusbar(_("Error reading lock file %s: Not enough data read"),
+ lockfilename);
+ return -1;
+ }
+ strncpy(lockprog, &lockbuf[2], 10);
+ lockpid = (unsigned char)lockbuf[25] * 256 + (unsigned char)lockbuf[24];
+ strncpy(lockuser, &lockbuf[28], 16);
#ifdef DEBUG
- fprintf(stderr, "lockpid = %d\n", lockpid);
- fprintf(stderr, "program name which created this lock file should be %s\n",
- lockprog);
- fprintf(stderr, "user which created this lock file should be %s\n",
- lockuser);
+ fprintf(stderr, "lockpid = %d\n", lockpid);
+ fprintf(stderr, "program name which created this lock file should be %s\n", lockprog);
+ fprintf(stderr, "user which created this lock file should be %s\n", lockuser);
#endif
/* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */
sprintf(promptstr, _("File %s is being edited (by %s with %s, PID %d); continue?"),
- filename, lockuser, lockprog, lockpid);
- ans = do_yesno_prompt(FALSE, promptstr);
- if (ans < 1) {
- blank_statusbar();
- return -1;
- }
+ filename, lockuser, lockprog, lockpid);
+ ans = do_yesno_prompt(FALSE, promptstr);
+ if (ans < 1) {
+ blank_statusbar();
+ return -1;
+ }
} else {
lockfiledir = mallocstrcpy(NULL, lockfilename);
lockfiledir = dirname(lockfiledir);
}
}
-
return write_lockfile(lockfilename, filename, FALSE);
}
#endif /* !NANO_TINY */
} else if (lockstatus == 0) {
quiet = TRUE;
}
- }
+ }
#endif
}
-
/* If the filename isn't blank, and we are not in NOREAD_MODE,
* open the file. Otherwise, treat it as a new file. */
rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ?
/* If opening the file succeeded, read it in. */
if (descriptor > 0)
read_file(f, descriptor, filename, FALSE, TRUE);
-
}
#endif /* !DISABLE_SPELLER */
/* Indicate the switch on the statusbar. */
if (quiet == FALSE)
statusbar(_("Switched to %s"),
- ((openfile->filename[0] == '\0') ? _("New Buffer") :
- openfile->filename));
+ ((openfile->filename[0] == '\0') ?
+ _("New Buffer") : openfile->filename));
#ifdef DEBUG
dump_filestruct(openfile->current);
#endif
/* Switch to the next file buffer. */
- switch_to_prevnext_buffer(TRUE, quiet);
+ switch_to_prevnext_buffer(TRUE, quiet);
/* Close the file buffer we had open before. */
unlink_opennode(openfile->prev);
full_filename = get_full_path(filename);
/* Okay, if we can't stat the path due to a component's
- permissions, just try the relative one. */
- if (full_filename == NULL
- || (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
- full_filename = mallocstrcpy(NULL, filename);
+ *permissions, just try the relative one. */
+ if (full_filename == NULL ||
+ (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
+ full_filename = mallocstrcpy(NULL, filename);
if ((fd = open(full_filename, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR |
- S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1
- || (f = fdopen(fd, "a")) == NULL)
+ S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1 ||
+ (f = fdopen(fd, "a")) == NULL)
ans = FALSE;
else
- fclose(f);
+ fclose(f);
close(fd);
free(full_filename);
full_filename = get_full_path(filename);
/* Okay, if we can't stat the path due to a component's
- permissions, just try the relative one. */
+ * permissions, just try the relative one. */
if (full_filename == NULL
|| (stat(full_filename, &fileinfo) == -1 && stat(filename, &fileinfo2) != -1))
full_filename = mallocstrcpy(NULL, filename);
if (stat(full_filename, &fileinfo) == -1) {
/* Well, maybe we can open the file even if the OS says it's
* not there. */
- if ((fd = open(filename, O_RDONLY)) != -1) {
+ if ((fd = open(filename, O_RDONLY)) != -1) {
if (!quiet)
statusbar(_("Reading File"));
free(full_filename);
strerror(errno));
beep();
return -1;
- } else {
+ } else {
/* The file is A-OK. Open it. */
*f = fdopen(fd, "rb");
{
static int i;
static char *prevfile = NULL; /* What was the last file we were
- * passed so we don't keep asking
- * this? Though maybe we should... */
+ * 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) "));
+ _("Failed to write backup file, continue saving? (Say N if unsure) "));
prevfile = mallocstrcpy(prevfile, filename);
}
return i;
free(backupname);
fclose(backup_file);
/* If we can't write to the backup, DONT go on, since
- whatever caused the backup file to fail (e.g. disk
- full may well cause the real file write to fail, which
- means we could lose both the backup and the original! */
+ * whatever caused the backup file to fail (e.g. disk
+ * full may well cause the real file write to fail, which
+ * means we could lose both the backup and the original! */
goto cleanup_and_exit;
}