nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] fix implicit is_file_writable() decl


From: Mike Frysinger
Subject: [Nano-devel] [PATCH] fix implicit is_file_writable() decl
Date: Mon, 2 Nov 2009 17:55:20 -0500

The is_file_writable() func is only used in files.c, so there is no
global/common decl, and it gets used before it is defined.  So we end
up getting a gcc implicit decl warning.

Simple fix is to move the func earlier up in the file before it is used.

Signed-off-by: Mike Frysinger <address@hidden>
---
 src/files.c |   83 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/src/files.c b/src/files.c
index bf96960..de69181 100644
--- a/src/files.c
+++ b/src/files.c
@@ -291,6 +291,47 @@ bool close_buffer(void)
 }
 #endif /* ENABLE_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.
+ */
+int is_file_writable(const char *filename)
+{
+    struct stat fileinfo, fileinfo2;
+    int fd;
+    FILE *f;
+    char *full_filename;
+    bool ans = TRUE;
+
+
+    if (ISSET(VIEW_MODE))
+       return TRUE;
+
+    assert(filename != NULL && f != NULL);
+
+    /* Get the specified file's full path. */
+    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);
+
+    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)
+       ans = FALSE;
+    else
+        fclose(f);
+    close(fd);
+
+    free(full_filename);
+    return ans;
+}
+
 /* We make a new line of text from buf.  buf is length buf_len.  If
  * first_line_ins is TRUE, then we put the new line at the top of the
  * file.  Otherwise, we assume prevnode is the last line of the file,
@@ -701,48 +742,6 @@ int open_file(const char *filename, bool newfie, FILE **f)
     return fd;
 }
 
-/* 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;
-    int fd;
-    FILE *f;
-    char *full_filename;
-    bool ans = TRUE;
-
-
-    if (ISSET(VIEW_MODE))
-       return TRUE;
-
-    assert(filename != NULL && f != NULL);
-
-    /* Get the specified file's full path. */
-    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);
-
-    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)
-       ans = FALSE;
-    else
-        fclose(f);
-    close(fd);
-
-    free(full_filename);
-    return ans;
-}
-
-
 /* This function will return the name of the first available extension
  * of a filename (starting with [name][suffix], then [name][suffix].1,
  * etc.).  Memory is allocated for the return value.  If no writable
-- 
1.6.5.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]