/* Initialize global GnuTLS state to defaults.
Call `gnutls-global-deinit' when GnuTLS usage is no longer needed.
Return zero on success. */
-static Lisp_Object
+Lisp_Object
emacs_gnutls_global_init (void)
{
int ret = GNUTLS_E_SUCCESS;
if (!gnutls_global_initialized)
- ret = gnutls_global_init ();
-
- gnutls_global_initialized = 1;
+ {
+ ret = gnutls_global_init ();
+ if (ret == GNUTLS_E_SUCCESS)
+ gnutls_global_initialized = 1;
+ }
return gnutls_make_error (ret);
}
#include "process.h"
#include "cm.h"
+#include "gnutls.h"
+#if 0x020c00 <= GNUTLS_VERSION_NUMBER
+# include <gnutls/crypto.h>
+#else
+# define emacs_gnutls_global_init() Qnil
+# define gnutls_rnd(level, data, len) (-1)
+#endif
+
#ifdef WINDOWSNT
#include <direct.h>
/* In process.h which conflicts with the local copy. */
init_random (void)
{
random_seed v;
- bool success = false;
-#ifndef WINDOWSNT
- int fd = emacs_open ("/dev/urandom", O_RDONLY | O_BINARY, 0);
- if (fd >= 0)
+ if (! (EQ (emacs_gnutls_global_init (), Qt)
+ && gnutls_rnd (GNUTLS_RND_NONCE, &v, sizeof v) == 0))
{
- success = emacs_read (fd, &v, sizeof v) == sizeof v;
- emacs_close (fd);
- }
+ bool success = false;
+#ifndef WINDOWSNT
+ int fd = emacs_open ("/dev/urandom", O_RDONLY | O_BINARY, 0);
+ if (0 <= fd)
+ {
+ success = emacs_read (fd, &v, sizeof v) == sizeof v;
+ emacs_close (fd);
+ }
#else
- success = w32_init_random (&v, sizeof v) == 0;
+ success = w32_init_random (&v, sizeof v) == 0;
#endif
- if (! success)
- {
- /* Fall back to current time value + PID. */
- struct timespec t = current_timespec ();
- v = getpid () ^ t.tv_sec ^ t.tv_nsec;
+ if (! success)
+ {
+ /* Fall back to current time value + PID. */
+ struct timespec t = current_timespec ();
+ v = getpid () ^ t.tv_sec ^ t.tv_nsec;
+ }
}
set_random_seed (v);
}
xfree (b);
}
- if (nbytes > INT_MAX)
+ if (INT_MAX < nbytes)
{
#ifdef EOVERFLOW
errno = EOVERFLOW;
{
emacs_write (STDERR_FILENO, "\nBacktrace:\n", 12);
backtrace_symbols_fd (buffer, npointers, STDERR_FILENO);
- if (npointers > bounded_limit)
+ if (bounded_limit < npointers)
emacs_write (STDERR_FILENO, "...\n", 4);
}
}
oflags |= O_CLOEXEC;
while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR)
QUIT;
- if (! O_CLOEXEC && fd >= 0)
+ if (! O_CLOEXEC && 0 <= fd)
fcntl (fd, F_SETFD, FD_CLOEXEC);
return fd;
}
unsigned long long frac = tval % hz;
int ns;
- if (s > TYPE_MAXIMUM (time_t))
+ if (TYPE_MAXIMUM (time_t) < s)
time_overflow ();
- if (ULLONG_MAX / TIMESPEC_RESOLUTION >= LONG_MAX - 1
+ if (LONG_MAX - 1 <= ULLONG_MAX / TIMESPEC_RESOLUTION
|| frac <= ULLONG_MAX / TIMESPEC_RESOLUTION)
ns = frac * TIMESPEC_RESOLUTION / hz;
else
record_unwind_protect_int (close_file_unwind, fd);
nread = emacs_read (fd, procbuf, sizeof procbuf - 1);
}
- if (nread > 0)
+ if (0 < nread)
{
procbuf[nread] = '\0';
p = procbuf;
if (nread)
{
/* We don't want trailing null characters. */
- for (p = cmdline + nread; p > cmdline && !p[-1]; p--)
+ for (p = cmdline + nread; cmdline < p && !p[-1]; p--)
continue;
/* Escape-quote whitespace and backslashes. */
q = cmdline + cmdline_size;
- while (p > cmdline)
+ while (cmdline < p)
{
char c = *--p;
*--q = c ? c : ' ';