Skip to content

Commit

Permalink
Merge pull request #1614 from bugsnag/PLAT-11044-remove-stat
Browse files Browse the repository at this point in the history
[Plat-11044] remove stat
  • Loading branch information
kstenerud authored Dec 8, 2023
2 parents aed032b + 2b80ff5 commit 1d0173a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 7 additions & 6 deletions Bugsnag/Helpers/BSGRunContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,14 @@ static int OpenFile(NSString *_Nonnull path) {
/// Loads the contents of the state file into memory and sets the
/// `bsg_lastRunContext` pointer if the contents are valid.
static void LoadLastRunContext(int fd) {
struct stat sb;
static struct BSGRunContext context;
uint8_t buff[SIZEOF_STRUCT+1]; // +1 to detect if the size grew

// Only expose previous state if size matches...
if (fstat(fd, &sb) == 0 && sb.st_size == SIZEOF_STRUCT) {
static struct BSGRunContext context;
if (read(fd, &context, SIZEOF_STRUCT) == SIZEOF_STRUCT &&
// ...and so does the structVersion
context.structVersion == BSGRUNCONTEXT_VERSION) {
if (read(fd, buff, sizeof(buff)) == SIZEOF_STRUCT) {
memcpy(&context, buff, SIZEOF_STRUCT);
// ...and so does the structVersion
if (context.structVersion == BSGRUNCONTEXT_VERSION) {
bsg_lastRunContext = &context;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_Jailbreak.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#ifndef bsg_jailbreak_h
#define bsg_jailbreak_h

#include <dirent.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <TargetConditionals.h>
Expand Down Expand Up @@ -195,9 +195,10 @@ static inline bool bsg_local_is_insert_libraries_env_var(const char* str) {
} \
\
const char* etc_apt_path = "/etc/apt"; \
struct stat st; \
if(stat(etc_apt_path, &st) == 0) { \
DIR *dirp = opendir(etc_apt_path); \
if(dirp) { \
etc_apt_exists = true; \
closedir(dirp); \
} \
\
for(int i = 0; environ[i] != NULL; i++) { \
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ GEM
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
optimist (3.0.1)
Expand Down Expand Up @@ -208,6 +210,7 @@ GEM
rexml (~> 3.2.4)

PLATFORMS
arm64-darwin-22
x86_64-darwin-19

DEPENDENCIES
Expand Down

0 comments on commit 1d0173a

Please sign in to comment.