mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Clean up POSIX.1 implementation of truncate.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2013-05-06 Roland McGrath <roland@hack.frob.com>
|
||||||
|
|
||||||
|
* sysdeps/posix/truncate.c (__truncate): Renamed from truncate.
|
||||||
|
Call __ names for open, ftruncate, and close.
|
||||||
|
For LENGTH==0 case, just use O_TRUNC rather than calling ftruncate.
|
||||||
|
(truncate): Define as weak alias.
|
||||||
|
|
||||||
2013-05-06 Joseph Myers <joseph@codesourcery.com>
|
2013-05-06 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
* math/gen-libm-test.pl (parse_args): Initialize x before each
|
* math/gen-libm-test.pl (parse_args): Initialize x before each
|
||||||
|
@ -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.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -22,20 +23,22 @@
|
|||||||
|
|
||||||
/* Truncate PATH to LENGTH bytes. */
|
/* Truncate PATH to LENGTH bytes. */
|
||||||
int
|
int
|
||||||
truncate (path, length)
|
__truncate (const char *path, off_t length)
|
||||||
const char *path;
|
|
||||||
off_t length;
|
|
||||||
{
|
{
|
||||||
int fd, ret, save;
|
int fd, ret, save;
|
||||||
|
|
||||||
fd = open (path, O_WRONLY);
|
fd = __open (path, O_WRONLY | (length == 0 ? O_TRUNC : 0));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = ftruncate (fd, length);
|
if (length == 0)
|
||||||
|
ret = 0;
|
||||||
|
else
|
||||||
|
ret = __ftruncate (fd, length);
|
||||||
save = errno;
|
save = errno;
|
||||||
(void) close (fd);
|
(void) __close (fd);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
__set_errno (save);
|
__set_errno (save);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
weak_alias (__truncate, truncate)
|
||||||
|
Reference in New Issue
Block a user