在Android 12电话中执行的程序中的下列代码:
struct timeval tv;
int ret = gettimeofday(&tv, NULL);
if (ret < 0)
printf("gettimeofday failed with %s\n", strerror(errno));
printf("%lu.%ld\n", tv.tv_sec, tv.tv_usec);返回
gettimeofday failed with Value too large for defined data type
1078605538.1此外,即使在循环中调用,秒和usecond也始终是常量。使用clock_gettime(CLOCK_REALTIME, &tv);完全相同的结果
一定是出了问题,因为根据手册,gettimeofday()不应该返回errno 75。
strace输出:
read(3, " \0\0\0\1\0\0\0\273\0\0\0\230\1\0\0\1\0\0\0\20\0\254\0\254\0\223\261zG\377F"..., 65536) = 199
clock_gettime(CLOCK_REALTIME, {tv_sec=3416400658881740019, tv_nsec=4632575514938983213}) = 0
dup(2) = 4
fcntl64(4, F_GETFL) = 0x20002 (flags O_RDWR|O_LARGEFILE)
statx(4, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS, stx_attributes=0, stx_mode=S_IFCHR|0600, stx_size=0, ...}) = 0
write(4, "gettimeofday: Value too large fo"..., 52gettimeofday: Value too large for defined data type
) = 52
close(4)
[ and same repeats, we are in a loop ] 发布于 2022-08-31 08:54:53
结果发现这是一个与Android有关的问题。从与arm-linux-gnueabi-gcc交叉编译转向使用ndk-build,这一问题得到了解决.
不完全确定根本原因,但是Makefile的一些东西被关闭了。
https://stackoverflow.com/questions/73546904
复制相似问题