| author | |
| committer | |
| log | 37fa6f955d5c2c9e89a5b95751f7c393db1fe822 |
| tree | 25cf7da56d0e917af583fa14827c5351d52da686 |
| parent | afb1652c50f0b25d45ccbbd7aa37f1c20cf61b0b |
Fixes 32-bit architectures.2 files changed, 91 insertions(+), 45 deletions(-)
lib/libc/glibc/sysdeps/unix/sysv/linux/stat_t64_cp.c created+75| ... | ... | @@ -0,0 +1,75 @@ |
| 1 | /* Struct stat/stat64 to stat/stat64 conversion for Linux. | |
| 2 | Copyright (C) 2020-2021 Free Software Foundation, Inc. | |
| 3 | This file is part of the GNU C Library. | |
| 4 | ||
| 5 | The GNU C Library is free software; you can redistribute it and/or | |
| 6 | modify it under the terms of the GNU Lesser General Public | |
| 7 | License as published by the Free Software Foundation; either | |
| 8 | version 2.1 of the License, or (at your option) any later version. | |
| 9 | ||
| 10 | The GNU C Library is distributed in the hope that it will be useful, | |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | Lesser General Public License for more details. | |
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public | |
| 16 | License along with the GNU C Library. If not, see | |
| 17 | <https://www.gnu.org/licenses/>. */ | |
| 18 | ||
| 19 | #include <stat_t64_cp.h> | |
| 20 | #include <string.h> | |
| 21 | #include <errno.h> | |
| 22 | #include <time.h> | |
| 23 | ||
| 24 | #if __TIMESIZE != 64 | |
| 25 | ||
| 26 | static inline bool | |
| 27 | in_time_t_range (__time64_t t) | |
| 28 | { | |
| 29 | time_t s = t; | |
| 30 | return s == t; | |
| 31 | } | |
| 32 | ||
| 33 | static inline struct timespec | |
| 34 | valid_timespec64_to_timespec (const struct __timespec64 ts64) | |
| 35 | { | |
| 36 | struct timespec ts; | |
| 37 | ||
| 38 | ts.tv_sec = (time_t) ts64.tv_sec; | |
| 39 | ts.tv_nsec = ts64.tv_nsec; | |
| 40 | ||
| 41 | return ts; | |
| 42 | } | |
| 43 | ||
| 44 | int | |
| 45 | __cp_stat64_t64_stat64 (const struct __stat64_t64 *st64_t64, | |
| 46 | 			struct stat64 *st64) | |
| 47 | { | |
| 48 | if (! in_time_t_range (st64_t64->st_atim.tv_sec) | |
| 49 | || ! in_time_t_range (st64_t64->st_mtim.tv_sec) | |
| 50 | || ! in_time_t_range (st64_t64->st_ctim.tv_sec)) | |
| 51 | { | |
| 52 | __set_errno (EOVERFLOW); | |
| 53 | return -1; | |
| 54 | } | |
| 55 | ||
| 56 | /* Clear both pad and reserved fields. */ | |
| 57 | memset (st64, 0, sizeof (*st64)); | |
| 58 | ||
| 59 | st64->st_dev = st64_t64->st_dev, | |
| 60 | st64->st_ino = st64_t64->st_ino; | |
| 61 | st64->st_mode = st64_t64->st_mode; | |
| 62 | st64->st_nlink = st64_t64->st_nlink; | |
| 63 | st64->st_uid = st64_t64->st_uid; | |
| 64 | st64->st_gid = st64_t64->st_gid; | |
| 65 | st64->st_rdev = st64_t64->st_rdev; | |
| 66 | st64->st_size = st64_t64->st_size; | |
| 67 | st64->st_blksize = st64_t64->st_blksize; | |
| 68 | st64->st_blocks = st64_t64->st_blocks; | |
| 69 | st64->st_atim = valid_timespec64_to_timespec (st64_t64->st_atim); | |
| 70 | st64->st_mtim = valid_timespec64_to_timespec (st64_t64->st_mtim); | |
| 71 | st64->st_ctim = valid_timespec64_to_timespec (st64_t64->st_ctim); | |
| 72 | ||
| 73 | return 0; | |
| 74 | } | |
| 75 | #endif |
src/glibc.zig+16-45| ... | ... | @@ -274,7 +274,10 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 274 | 274 | const linux_prefix = lib_libc_glibc ++ |
| 275 | 275 | "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s; |
| 276 | 276 | const Flavor = enum { nonshared, shared }; |
| 277 | const Dep = struct { path: []const u8, flavor: Flavor }; | |
| 277 | const Dep = struct { | |
| 278 | path: []const u8, | |
| 279 | flavor: Flavor = .shared, | |
| 280 | }; | |
| 278 | 281 | const deps = [_]Dep{ |
| 279 | 282 | .{ |
| 280 | 283 | .path = lib_libc_glibc ++ "stdlib" ++ s ++ "atexit.c", |
| ... | ... | @@ -284,46 +287,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 284 | 287 | .path = lib_libc_glibc ++ "stdlib" ++ s ++ "at_quick_exit.c", |
| 285 | 288 | .flavor = .nonshared, |
| 286 | 289 | }, |
| 287 | .{ | |
| 288 | .path = linux_prefix ++ "stat.c", | |
| 289 | .flavor = .shared, | |
| 290 | }, | |
| 291 | .{ | |
| 292 | .path = linux_prefix ++ "fstat.c", | |
| 293 | .flavor = .shared, | |
| 294 | }, | |
| 295 | .{ | |
| 296 | .path = linux_prefix ++ "lstat.c", | |
| 297 | .flavor = .shared, | |
| 298 | }, | |
| 299 | .{ | |
| 300 | .path = linux_prefix ++ "stat64.c", | |
| 301 | .flavor = .shared, | |
| 302 | }, | |
| 303 | .{ | |
| 304 | .path = linux_prefix ++ "fstat64.c", | |
| 305 | .flavor = .shared, | |
| 306 | }, | |
| 307 | .{ | |
| 308 | .path = linux_prefix ++ "lstat64.c", | |
| 309 | .flavor = .shared, | |
| 310 | }, | |
| 311 | .{ | |
| 312 | .path = linux_prefix ++ "fstatat.c", | |
| 313 | .flavor = .shared, | |
| 314 | }, | |
| 315 | .{ | |
| 316 | .path = linux_prefix ++ "fstatat64.c", | |
| 317 | .flavor = .shared, | |
| 318 | }, | |
| 319 | .{ | |
| 320 | .path = linux_prefix ++ "mknodat.c", | |
| 321 | .flavor = .shared, | |
| 322 | }, | |
| 323 | .{ | |
| 324 | .path = lib_libc_glibc ++ "io" ++ s ++ "mknod.c", | |
| 325 | .flavor = .shared, | |
| 326 | }, | |
| 327 | 290 | .{ |
| 328 | 291 | .path = lib_libc_glibc ++ "sysdeps" ++ s ++ "pthread" ++ s ++ "pthread_atfork.c", |
| 329 | 292 | .flavor = .nonshared, |
| ... | ... | @@ -332,10 +295,18 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 332 | 295 | .path = lib_libc_glibc ++ "debug" ++ s ++ "stack_chk_fail_local.c", |
| 333 | 296 | .flavor = .nonshared, |
| 334 | 297 | }, |
| 335 | .{ | |
| 336 | .path = lib_libc_glibc ++ "csu" ++ s ++ "errno.c", | |
| 337 | .flavor = .shared, | |
| 338 | }, | |
| 298 | .{ .path = lib_libc_glibc ++ "csu" ++ s ++ "errno.c" }, | |
| 299 | .{ .path = linux_prefix ++ "stat.c" }, | |
| 300 | .{ .path = linux_prefix ++ "fstat.c" }, | |
| 301 | .{ .path = linux_prefix ++ "lstat.c" }, | |
| 302 | .{ .path = linux_prefix ++ "stat64.c" }, | |
| 303 | .{ .path = linux_prefix ++ "fstat64.c" }, | |
| 304 | .{ .path = linux_prefix ++ "lstat64.c" }, | |
| 305 | .{ .path = linux_prefix ++ "fstatat.c" }, | |
| 306 | .{ .path = linux_prefix ++ "fstatat64.c" }, | |
| 307 | .{ .path = linux_prefix ++ "mknodat.c" }, | |
| 308 | .{ .path = lib_libc_glibc ++ "io" ++ s ++ "mknod.c" }, | |
| 309 | .{ .path = linux_prefix ++ "stat_t64_cp.c" }, | |
| 339 | 310 | }; |
| 340 | 311 | |
| 341 | 312 | var c_source_files: [deps.len]Compilation.CSourceFile = undefined; |