X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fish%2Fedit.c;h=3fc41fb1c34d7c0c42fa42ecaaf8255ce7eb18a5;hp=c72ad1d81872dc16c7b56bc3e6d27aef330fb8b6;hb=89486c50eaeb8b1cc5a6ff388cb47e859f8565d1;hpb=19a1382fc9317ab88cdbf1dde76a8015868af51d diff --git a/fish/edit.c b/fish/edit.c index c72ad1d..3fc41fb 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -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 @@ -30,7 +30,7 @@ /* guestfish edit command, suggested by Ján Ondrej, implemented by RWMJ */ 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; @@ -80,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); @@ -88,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"); @@ -138,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); @@ -148,7 +149,7 @@ do_edit (const char *cmd, int argc, char *argv[]) unlink (filename); /* Changed? */ - if (strlen (content) == size && strncmp (content, content_new, size) == 0) { + if (strlen (content) == size && STREQLEN (content, content_new, size)) { free (content); free (content_new); return 0;