cut_to_eol()
- Fix inaccurate comment. (DLR)
- files.c:
+ get_full_path()
+ - Rework handling of the results of getcwd() in order to avoid
+ segfaults if they fail, and to remove uses of the nonportable
+ GNU extension where passing a size of 0 will get a string as
+ long as we need. (DLR)
do_browser()
- Rename variable lineno to fileline to avoid confusion. (DLR)
+ do_browse_from()
+ - Rework handling of the results of getcwd() in order to avoid
+ segfaults if they fail, and to remove uses of the nonportable
+ GNU extension where passing a size of 0 will get a string as
+ long as we need. (DLR)
- nano.c:
help_init()
- When calculating allocsize, take multibyte characters into
- Instead of breaking a line at a space and readding the space
afterwards, just break the line after the space, as it's more
efficient. (DLR)
+- nano.h:
+ - Define PATH_MAX as 4096 if it isn't defined, as passing a size
+ of 0 to get a string as long as we need is a nonportable GNU
+ extension, and hence it won't work on non-GNU systems that
+ don't define PATH_MAX. (DLR)
- utils.c:
regexec_safe()
- Rename to safe_regexec() for consistency. (DLR)
return NULL;
/* Get the current directory. */
-#if PATH_MAX != -1
d_here = charalloc(PATH_MAX + 1);
-#else
- d_here = NULL;
-#endif
d_here = getcwd(d_here, PATH_MAX + 1);
-#if PATH_MAX != -1
- align(&d_here);
-#endif
if (d_here != NULL) {
const char *last_slash;
bool path_only;
struct stat fileinfo;
+ align(&d_here);
+
/* If the current directory isn't "/", tack a slash onto the end
* of it. */
if (strcmp(d_here, "/") != 0) {
} else {
/* Get the full path and save it in d_there. */
free(d_there);
-#if PATH_MAX != -1
+
d_there = charalloc(PATH_MAX + 1);
-#else
- d_there = NULL;
-#endif
d_there = getcwd(d_there, PATH_MAX + 1);
-#if PATH_MAX != -1
- align(&d_there);
-#endif
- if (d_there == NULL)
+ if (d_there != NULL) {
+ align(&d_there);
+
+ if (strcmp(d_there, "/") != 0) {
+ /* Make sure d_there ends in a slash. */
+ d_there = charealloc(d_there,
+ strlen(d_there) + 2);
+ strcat(d_there, "/");
+ }
+ } else
/* If we couldn't get the full path, set path_only
* to TRUE so that we clean up correctly, free all
* allocated memory, and return NULL. */
path_only = TRUE;
- else if (strcmp(d_there, "/") != 0) {
- /* Make sure d_there ends in a slash. */
- d_there = charealloc(d_there, strlen(d_there) + 2);
- strcat(d_there, "/");
- }
/* Finally, go back to the path specified in d_here,
* where we were before. */
* d_there_file contains the filename portion of the answer. If
* this is the case, tack d_there_file onto the end of
* d_there, so that d_there contains the complete answer. */
- if (!path_only && d_there) {
+ if (!path_only && d_there != NULL) {
d_there = charealloc(d_there, strlen(d_there) +
strlen(d_there_file) + 1);
strcat(d_there, d_there_file);
struct stat st;
char *path;
/* This holds the tilde-expanded version of inpath. */
- DIR *dir;
+ DIR *dir = NULL;
assert(inpath != NULL);
striponedir(path);
if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
free(path);
-#if PATH_MAX != -1
+
path = charalloc(PATH_MAX + 1);
-#else
- path = NULL;
-#endif
path = getcwd(path, PATH_MAX + 1);
-#if PATH_MAX != -1
- align(&path);
-#endif
+
+ if (path != NULL)
+ align(&path);
}
}
}
#endif
- dir = opendir(path);
+ if (path != NULL)
+ dir = opendir(path);
+
if (dir == NULL) {
beep();
free(path);