- Stat full_path, not path (Steven Kneizys).
read_file()
- Abort if we read a file of 0 lines (num_lines == 0), fixes BUG #70.
+ - Reverse tests to stop segfault on editing a new file of 0
+ lines (David Benbennick)
+ - Change input var to one char instead of array (David Benbennick).
- nano.c:
do_justify()
- More fixes for indented justify (David Benbennick).
resetty();
endwin();
perror(filename);
+ total_refresh();
+ return -1;
}
if (!size)
return 0;
{
long size;
int num_lines = 0;
- char input[2]; /* buffer */
+ char input; /* current input character */
char *buf;
long i = 0, bufx = 128;
filestruct *fileptr = current, *tmp = NULL;
current = fileage;
line1ins = 1;
}
- input[1] = 0;
/* Read the entire file into file struct */
- while ((size = read_byte(fd, filename, input)) > 0) {
+ while ((size = read_byte(fd, filename, &input)) > 0) {
- if (input[0] == '\n') {
+ if (input == '\n') {
fileptr = read_line(buf, fileptr, &line1ins);
num_lines++;
buf[0] = 0;
i = 0;
#ifndef NANO_SMALL
- } else if (!ISSET(NO_CONVERT) && input[0] >= 0 && input[0] <= 31
- && input[0] != '\t' && input[0] != '\r'
- && input[0] != '\n')
+ } else if (!ISSET(NO_CONVERT) && input >= 0 && input <= 31
+ && input != '\t' && input != '\r'
+ && input != '\n')
/* If the file has binary chars in it, don't stupidly
assume it's a DOS or Mac formatted file! */
SET(NO_CONVERT);
fileformat = 2;
fileptr = read_line(buf, fileptr, &line1ins);
num_lines++;
- buf[0] = input[0];
+ buf[0] = input;
buf[1] = 0;
i = 1;
#endif
buf = nrealloc(buf, bufx + 128);
bufx += 128;
}
- buf[i] = input[0];
+ buf[i] = input;
buf[i + 1] = 0;
i++;
}
buf[0] = 0;
}
- /* Did we try to insert a file of 0 bytes? */
- if (num_lines == 0)
- {
- statusbar(_("Read %d lines"), 0);
- return 1;
- }
-
/* Did we even GET a file if we don't already have one? */
if (totsize == 0 || fileptr == NULL) {
new_file();
return 1;
}
+ /* Did we try to insert a file of 0 bytes? */
+ if (num_lines == 0)
+ {
+ statusbar(_("Read %d lines"), 0);
+ return 1;
+ }
+
if (current != NULL) {
fileptr->next = current;
current->prev = fileptr;
dup2(fd[1], fileno(stderr));
/* If execl() returns at all, there was an error. */
- execl("/bin/sh","/bin/sh","-c",command,0);
+ execl("/bin/sh","sh","-c",command,0);
exit(0);
}