convert uses of strcasecmp to STRCASEEQ
[libguestfs.git] / fish / edit.c
index 5519bb9..d30b3ca 100644 (file)
@@ -1,5 +1,5 @@
 /* guestfish - the filesystem interactive shell
- * Copyright (C) 2009 Red Hat Inc. 
+ * Copyright (C) 2009 Red Hat Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 /* guestfish edit command, suggested by Ján Ondrej, implemented by RWMJ */
 
-static int
-xwrite (int fd, const void *buf, size_t len)
-{
-  int r;
-
-  while (len > 0) {
-    r = write (fd, buf, len);
-    if (r == -1) {
-      perror ("write");
-      return -1;
-    }
-    buf += r;
-    len -= r;
-  }
-
-  return 0;
-}
-
 static char *
-load_file (const char *filename, int *len_r)
+load_file (const char *filename, size_t *len_r)
 {
   int fd, r, start;
   char *content = NULL, *p;
@@ -98,7 +80,7 @@ do_edit (const char *cmd, int argc, char *argv[])
   char buf[256];
   const char *editor;
   char *content, *content_new;
-  int r, fd, size;
+  int r, fd;
 
   if (argc != 1) {
     fprintf (stderr, _("use '%s filename' to edit a file\n"), cmd);
@@ -106,9 +88,9 @@ do_edit (const char *cmd, int argc, char *argv[])
   }
 
   /* Choose an editor. */
-  if (strcasecmp (cmd, "vi") == 0)
+  if (STRCASEEQ (cmd, "vi"))
     editor = "vi";
-  else if (strcasecmp (cmd, "emacs") == 0)
+  else if (STRCASEEQ (cmd, "emacs"))
     editor = "emacs -nw";
   else {
     editor = getenv ("EDITOR");
@@ -156,6 +138,7 @@ do_edit (const char *cmd, int argc, char *argv[])
   }
 
   /* Reload it. */
+  size_t size;
   content_new = load_file (filename, &size);
   if (content_new == NULL) {
     unlink (filename);