diff options
author | Roland McGrath <roland@hack.frob.com> | 2013-05-06 14:56:13 -0700 |
---|---|---|
committer | Roland McGrath <roland@hack.frob.com> | 2013-05-06 14:56:13 -0700 |
commit | c74058300c76d7afa316453c03e5776b3a9155a8 (patch) | |
tree | 5a349eea3a6f47fcaae863bc91bc2260fb22d886 /sysdeps/posix | |
parent | 9ea3513c917e04ba6cb4a6ce0b9d455f566a1d3f (diff) | |
download | glibc-c74058300c76d7afa316453c03e5776b3a9155a8.tar.gz glibc-c74058300c76d7afa316453c03e5776b3a9155a8.tar.xz glibc-c74058300c76d7afa316453c03e5776b3a9155a8.zip |
Clean up POSIX.1 implementation of truncate.
Diffstat (limited to 'sysdeps/posix')
-rw-r--r-- | sysdeps/posix/truncate.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/sysdeps/posix/truncate.c b/sysdeps/posix/truncate.c index ae29be8106..7ef1400eb5 100644 --- a/sysdeps/posix/truncate.c +++ b/sysdeps/posix/truncate.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1995-2013 Free Software Foundation, Inc. +/* Truncate a file given by name. Generic POSIX.1 version. + Copyright (C) 1995-2013 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -22,20 +23,22 @@ /* Truncate PATH to LENGTH bytes. */ int -truncate (path, length) - const char *path; - off_t length; +__truncate (const char *path, off_t length) { int fd, ret, save; - fd = open (path, O_WRONLY); + fd = __open (path, O_WRONLY | (length == 0 ? O_TRUNC : 0)); if (fd < 0) return -1; - ret = ftruncate (fd, length); + if (length == 0) + ret = 0; + else + ret = __ftruncate (fd, length); save = errno; - (void) close (fd); + (void) __close (fd); if (ret < 0) __set_errno (save); return ret; } +weak_alias (__truncate, truncate) |