]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/posix/truncate.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / posix / truncate.c
index d96f5fba55cec0c85fcc8503aedf37a5b1138988..82a77b5a9a118d7fa439a20f3e92d7425dc9b964 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Truncate a file given by name.  Generic POSIX.1 version.
+   Copyright (C) 1995-2016 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
 
 /* 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)