(erase_file): don't malloc

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6044 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1999-04-25 14:55:49 +00:00
parent 28928b2ef9
commit b380f51a81

View File

@@ -97,7 +97,7 @@ erase_file(const char *filename)
{ {
int fd; int fd;
off_t pos; off_t pos;
char *p; char buf[128];
fd = open(filename, O_RDWR | O_BINARY); fd = open(filename, O_RDWR | O_BINARY);
if(fd < 0){ if(fd < 0){
@@ -108,10 +108,9 @@ erase_file(const char *filename)
} }
pos = lseek(fd, 0, SEEK_END); pos = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
p = (char*) malloc(pos); memset(buf, 0, sizeof(buf));
memset(p, 0, pos); while(pos > 0)
write(fd, p, pos); pos -= write(fd, buf, sizeof(buf));
free(p);
close(fd); close(fd);
unlink(filename); unlink(filename);
return 0; return 0;