Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik M. Bray <erik.m.bray@gmail.com>2017-11-02 18:45:35 +0300
committerCorinna Vinschen <corinna@vinschen.de>2017-11-02 20:01:01 +0300
commit94854321bb79603b3adcf42093031c7e85c81e0a (patch)
tree9a0499bdf95aff378b7bf8c97bfde0840b2b0544
parent8c8cdd9ad72b07c1edefb5264cdcb4927700e813 (diff)
posix_fallocate() *returns* error codes but does not set errno
Also updates the fhandler_*::ftruncate implementations to adhere to the same semantics. The error handling semantics of those syscalls that use fhandler_*::ftruncate are moved to the implementations of those syscalls ( in particular ftruncate() and friends still set errno and return -1 on error but that logic is handled in the syscall implementation).
-rw-r--r--winsup/cygwin/fhandler.cc3
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc17
-rw-r--r--winsup/cygwin/pipe.cc3
-rw-r--r--winsup/cygwin/syscalls.cc11
4 files changed, 16 insertions, 18 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index d719b7ca2..5b7d002bd 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1771,8 +1771,7 @@ fhandler_base::fadvise (off_t offset, off_t length, int advice)
int
fhandler_base::ftruncate (off_t length, bool allow_truncate)
{
- set_errno (EINVAL);
- return -1;
+ return EINVAL;
}
int
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 252dc660c..bc8fead5e 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -1112,14 +1112,14 @@ fhandler_disk_file::fadvise (off_t offset, off_t length, int advice)
int
fhandler_disk_file::ftruncate (off_t length, bool allow_truncate)
{
- int res = -1;
+ int res = 0;
if (length < 0 || !get_handle ())
- set_errno (EINVAL);
+ res = EINVAL;
else if (pc.isdir ())
- set_errno (EISDIR);
+ res = EISDIR;
else if (!(get_access () & GENERIC_WRITE))
- set_errno (EBADF);
+ res = EBADF;
else
{
NTSTATUS status;
@@ -1130,10 +1130,7 @@ fhandler_disk_file::ftruncate (off_t length, bool allow_truncate)
status = NtQueryInformationFile (get_handle (), &io, &fsi, sizeof fsi,
FileStandardInformation);
if (!NT_SUCCESS (status))
- {
- __seterrno_from_nt_status (status);
- return -1;
- }
+ return geterrno_from_nt_status (status);
/* If called through posix_fallocate, silently succeed if length
is less than the file's actual length. */
@@ -1159,9 +1156,7 @@ fhandler_disk_file::ftruncate (off_t length, bool allow_truncate)
&feofi, sizeof feofi,
FileEndOfFileInformation);
if (!NT_SUCCESS (status))
- __seterrno_from_nt_status (status);
- else
- res = 0;
+ res = geterrno_from_nt_status (status);
}
return res;
}
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index 8738d34b9..f1eace6a6 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -171,8 +171,7 @@ fhandler_pipe::fadvise (off_t offset, off_t length, int advice)
int
fhandler_pipe::ftruncate (off_t length, bool allow_truncate)
{
- set_errno (allow_truncate ? EINVAL : ESPIPE);
- return -1;
+ return allow_truncate ? EINVAL : ESPIPE;
}
char *
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index d0d735bde..1807afcc6 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2946,16 +2946,16 @@ posix_fadvise (int fd, off_t offset, off_t len, int advice)
extern "C" int
posix_fallocate (int fd, off_t offset, off_t len)
{
- int res = -1;
+ int res = 0;
if (offset < 0 || len == 0)
- set_errno (EINVAL);
+ res = EINVAL;
else
{
cygheap_fdget cfd (fd);
if (cfd >= 0)
res = cfd->ftruncate (offset + len, false);
else
- set_errno (EBADF);
+ res = EBADF;
}
syscall_printf ("%R = posix_fallocate(%d, %D, %D)", res, fd, offset, len);
return res;
@@ -2968,6 +2968,11 @@ ftruncate64 (int fd, off_t length)
cygheap_fdget cfd (fd);
if (cfd >= 0)
res = cfd->ftruncate (length, true);
+ if (res)
+ {
+ set_errno (res);
+ res = -1;
+ }
else
set_errno (EBADF);
syscall_printf ("%R = ftruncate(%d, %D)", res, fd, length);