diff options
author | Tim Rice <tim@multitalents.net> | 2002-05-07 19:51:31 -0700 |
---|---|---|
committer | Tim Rice <tim@multitalents.net> | 2002-05-07 19:51:31 -0700 |
commit | 4bd2a1989073dcf353e8e4801029f9b6873158df (patch) | |
tree | c367bb516838b2284f00286f53242607c08c06e5 /openbsd-compat/bsd-misc.c | |
parent | f762a4bea554a9ff4dc59b9456c7e1a2379310b3 (diff) |
Add truncate() emulation to address Bug 208
Diffstat (limited to 'openbsd-compat/bsd-misc.c')
-rw-r--r-- | openbsd-compat/bsd-misc.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 7bf46dd7..237f9393 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -24,7 +24,7 @@ #include "includes.h" -RCSID("$Id: bsd-misc.c,v 1.5 2001/10/10 20:38:56 mouring Exp $"); +RCSID("$Id: bsd-misc.c,v 1.6 2002/05/08 02:51:32 tim Exp $"); char *get_progname(char *argv0) { @@ -99,3 +99,22 @@ int utimes(char *filename, struct timeval *tvp) return(utime(filename, &ub)); } #endif + +#ifndef HAVE_TRUNCATE +int truncate (const char *path, off_t length) +{ + int fd, ret, saverrno; + + fd = open(path, O_WRONLY); + if (fd < 0) + return -1; + + ret = ftruncate(fd, length); + saverrno = errno; + (void) close (fd); + if (ret == -1) + errno = saverrno; + return(ret); +} +#endif /* HAVE_TRUNCATE */ + |