mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 08:56:10 +08:00
croak if gettimeofday() fails
There is no conceivable way in which timef()'s invocation of gettimeofday() can fail where it makes sense to continue running. Yes, one such, legitimate, failure mode is a 32-bit kernel and the date is greater than 2038-01-19 03:14:07. If you're running a fish binary on such a system it's time to upgrade. Otherwise, either the hardware or OS is broken. Fixes #3167.
This commit is contained in:
parent
0d6bdb38e6
commit
b2a2705df4
@ -1648,19 +1648,13 @@ void format_size_safe(char buff[128], unsigned long long sz) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the number of seconds from the UNIX epoch, with subsecond precision. This function uses
|
||||
/// the gettimeofday function and will have the same precision as that function.
|
||||
double timef() {
|
||||
struct timeval tv;
|
||||
int time_res = gettimeofday(&tv, 0);
|
||||
|
||||
if (time_res) {
|
||||
// Fixme: What on earth is the correct parameter value for NaN? The man pages and the
|
||||
// standard helpfully state that this parameter is implementation defined. Gcc gives a
|
||||
// warning if a null pointer is used. But not even all mighty Google gives a hint to what
|
||||
// value should actually be returned.
|
||||
return nan("");
|
||||
}
|
||||
|
||||
return (double)tv.tv_sec + 0.000001 * tv.tv_usec;
|
||||
VOMIT_ON_FAILURE(gettimeofday(&tv, 0));
|
||||
// return (double)tv.tv_sec + 0.000001 * tv.tv_usec;
|
||||
return (double)tv.tv_sec + 1e-6 * tv.tv_usec;
|
||||
}
|
||||
|
||||
void exit_without_destructors(int code) { _exit(code); }
|
||||
|
@ -744,8 +744,7 @@ int create_directory(const wcstring &d);
|
||||
void bugreport();
|
||||
|
||||
/// Return the number of seconds from the UNIX epoch, with subsecond precision. This function uses
|
||||
/// the gettimeofday function, and will have the same precision as that function. If an error
|
||||
/// occurs, NAN is returned.
|
||||
/// the gettimeofday function and will have the same precision as that function.
|
||||
double timef();
|
||||
|
||||
/// Call the following function early in main to set the main thread. This is our replacement for
|
||||
|
Loading…
x
Reference in New Issue
Block a user