X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fzero.c;h=4d06505260379d8adcecb6d31f2319c5169e0ef7;hp=9d793e1509ec7b6a6b41cf6582dced4600902206;hb=bba019781a0df3744ccbfe9e580786b66dc9afa9;hpb=56bef498f46ac3dd580f4bde3c8f3ed2fe688826 diff --git a/daemon/zero.c b/daemon/zero.c index 9d793e1..4d06505 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * 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 @@ -28,13 +28,11 @@ #include "actions.h" int -do_zero (char *device) +do_zero (const char *device) { int fd, i; char buf[4096]; - IS_DEVICE (device, -1); - fd = open (device, O_WRONLY); if (fd == -1) { reply_with_perror ("%s", device); @@ -44,9 +42,16 @@ do_zero (char *device) memset (buf, 0, sizeof buf); for (i = 0; i < 32; ++i) - (void) write (fd, buf, sizeof buf); - - close (fd); + if (write (fd, buf, sizeof buf) != sizeof buf) { + reply_with_perror ("write: %s", device); + close (fd); + return -1; + } + + if (close (fd) == -1) { + reply_with_perror ("close: %s", device); + return -1; + } return 0; }