diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2014-08-31 21:54:13 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2014-08-31 21:54:13 +0200 |
commit | 98a1d6660bc329726f59d58f934e221dbaff6580 (patch) | |
tree | 3cc951951b5423358c7fb9a81f68521ffd93340f /sysdeps | |
parent | 0b01862fafb75fbf7bb272466e5c7d55cb3f83a3 (diff) |
Add handling code, untested for now
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/mach/hurd/fcntl.c | 32 | ||||
-rw-r--r-- | sysdeps/mach/hurd/flockconv.c | 78 |
2 files changed, 108 insertions, 2 deletions
diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c index ccc53dbb2d..9b576e53d1 100644 --- a/sysdeps/mach/hurd/fcntl.c +++ b/sysdeps/mach/hurd/fcntl.c @@ -22,6 +22,8 @@ #include <stdarg.h> #include <sys/file.h> /* XXX for LOCK_* */ +#include "flockconv.c" + /* Perform file control operations on FD. */ int __libc_fcntl (int fd, int cmd, ...) @@ -181,12 +183,38 @@ __libc_fcntl (int fd, int cmd, ...) return __flock (fd, cmd); } + case F_GETLK64: case F_SETLK64: case F_SETLKW64: { - struct flock64 *fl = va_arg (ap, struct flock64 *); - /* TODO: implementation */ + struct flock64 *fl64 = va_arg (ap, struct flock64 *); + struct flock fl; + + if (flock64_conv (&fl, fl64)) + { + result = -1; + break; + } + + switch (cmd) + { + case F_GETLK64: + result = fcntl (fd, F_GETLK, &fl); + if (flock_conv (fl64, &fl)) + result = -1; + break; + + case F_SETLK64: + result = fcntl (fd, F_SETLK, &fl); + break; + + case F_SETLKW64: + result = fcntl (fd, F_SETLKW, &fl); + break; + } + + break; } case F_GETFL: /* Get per-open flags. */ diff --git a/sysdeps/mach/hurd/flockconv.c b/sysdeps/mach/hurd/flockconv.c new file mode 100644 index 0000000000..acd2d6c1f5 --- /dev/null +++ b/sysdeps/mach/hurd/flockconv.c @@ -0,0 +1,78 @@ +/* Convert between `struct stat' format, and `struct stat64' format. + Copyright (C) 2014 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <errno.h> +#include <bits/fcntl.h> + +static intline int +flock64_conv (struct flock *buf, const struct flock64 *buf64) +{ + if (sizeof *buf == sizeof *buf64 + && sizeof buf->l_start == sizeof buf64->l_start + && sizeof buf->l_end == sizeof buf64->l_end) + { + *buf = *(struct flock *) buf64; + return 0; + } + + buf->l_type = buf64->l_type; + buf->l_whence = buf64->l_whence; + buf->l_start = buf64->l_start; + buf->l_len = buf64->l_len; + buf->l_pid = buf64->l_pid; + + if ((sizeof buf->l_start != sizeof buf64->l_start + && buf->l_start != buf64->l_start) + || (sizeof buf->l_len != sizeof buf64->l_len + && buf->l_len != buf64->l_len)) + { + __set_errno (EOVERFLOW); + return -1; + } + + return 0; +} + +static intline int +flock_conv (struct flock64 *buf64, const struct flock *buf) +{ + if (sizeof *buf == sizeof *buf64 + && sizeof buf->l_start == sizeof buf64->l_start + && sizeof buf->l_end == sizeof buf64->l_end) + { + *buf64 = *(struct flock *) buf; + return 0; + } + + buf64->l_type = buf->l_type; + buf64->l_whence = buf->l_whence; + buf64->l_start = buf->l_start; + buf64->l_len = buf->l_len; + buf64->l_pid = buf->l_pid; + + if ((sizeof buf->l_start != sizeof buf64->l_start + && buf->l_start != buf64->l_start) + || (sizeof buf->l_len != sizeof buf64->l_len + && buf->l_len != buf64->l_len)) + { + __set_errno (EOVERFLOW); + return -1; + } + + return 0; +} |