X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=fd.c;fp=fd.c;h=920bce9cf49a132a868c1983f990cd7fd124748a;hb=e7fdbaf015655af4eec7e4655b9306e1db862a40;hp=b889d9d2144a4ad78cf6442997d80fec643aad87;hpb=af89ce791ead29cb2a86e257f8e8d113c6ac205f;p=osl.git diff --git a/fd.c b/fd.c index b889d9d..920bce9 100644 --- a/fd.c +++ b/fd.c @@ -322,3 +322,34 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) return p; } +/** + * A wrapper for truncate(2) + * + * \param path Name of the regular file to truncate + * \param size Number of bytes to \b shave \b off + * + * Truncate the regular file named by \a path by \a size bytes. + * + * \return Standard. + * + * \sa truncate(2) + */ +int para_truncate(const char *path, off_t size) +{ + int ret; + struct stat statbuf; + + ret = -E_OSL_STAT; + if (stat(path, &statbuf) < 0) + goto out; + ret = -E_OSL_BAD_SIZE; + if (statbuf.st_size < size) + goto out; + ret = -E_OSL_TRUNC; + if (truncate(path, statbuf.st_size - size) < 0) + goto out; + ret = 1; +out: + return ret; +} +