Skip to content

Commit

Permalink
Portal: Add getrandom fallback for old versions of GLIBC (#86)
Browse files Browse the repository at this point in the history
When compiling against a version of GLIBC before 2.25, `getrandom` is not available. This change provides a fallback to perform the relevant syscall directly.
  • Loading branch information
topolarity authored Mar 23, 2023
1 parent 43fe9cf commit 44e63d5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/nfd_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/random.h> // for the random token string
#include <unistd.h> // for access()
#include <unistd.h> // for access()

#if !defined(__has_include) || !defined(__linux__)
#include <sys/random.h> // for getrandom() - the random token string
#elif __has_include(<sys/random.h>)
#include <sys/random.h>
#else // for GLIBC < 2.25
#include <sys/syscall.h>
#define getrandom(buf, sz, flags) syscall(SYS_getrandom, buf, sz, flags)
#endif

#include "nfd.h"

Expand Down

0 comments on commit 44e63d5

Please sign in to comment.