Rizin
unix-like reverse engineering framework and cli tools
liboverride-test.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "zip.h"

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 59 of file liboverride-test.c.

59  {
60  int verbose = 0;
61  int error_code;
62 
63  if (argc > 1 && strcmp(argv[1], "-v") == 0) {
64  verbose = 1;
65  }
66 
67  if (getenv("LIBOVERRIDE_SET") == NULL) {
68  char *cwd = getcwd(NULL, 0);
69  char *so = (char *)malloc(strlen(cwd) + 64);
70  if (so == NULL) {
71  if (verbose) {
72  printf("malloc failed\n");
73  }
74  exit(2);
75  }
76  sprintf(so, "%s/libliboverride.so", cwd);
77  setenv("LIBOVERRIDE_SET", "1", 1);
78  setenv("LD_PRELOAD", so, 1);
79  execv(argv[0], (void *)argv);
80  if (verbose) {
81  printf("exec failed: %s\n", strerror(errno));
82  }
83  exit(2);
84  }
85 
86  if (zip_open("nosuchfile", 0, &error_code) != NULL) {
87  /* We expect failure. */
88  if (verbose) {
89  printf("open succeeded\n");
90  }
91  exit(1);
92  }
93  if (error_code != 32000) {
94  /* Override didn't take, we didn't get its magic error code. */
95  if (verbose) {
96  printf("got unexpected error %d\n", error_code);
97  }
98  exit(1);
99  }
100 
101  if (verbose) {
102  printf("success\n");
103  }
104  exit(0);
105 }
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
sprintf
Definition: kernel.h:365
ZIP_EXTERN zip_t *_Nullable zip_open(const char *_Nonnull, int, int *_Nullable)
Definition: zip_open.c:54
void * malloc(size_t size)
Definition: malloc.c:123
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
char * getenv()
static int verbose
Definition: z80asm.c:73

References argv, test-lz4-speed::cwd, test-lz4-versions::error_code, test-lz4-list::exit, getenv(), malloc(), NULL, printf(), sprintf, verbose, and zip_open().