mbed-os/test/mbed-client-randlib/unittest/stubs/open_stub.c

28 lines
639 B
C

/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
*/
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
bool allow_open = true;
int __real_open(const char *path, int flags, ...);
int __wrap_open(const char *path, int flags, ...)
{
if (allow_open) {
if (flags & O_CREAT) {
va_list vl;
va_start(vl, flags);
mode_t mode = va_arg(vl, mode_t);
va_end(vl);
return __real_open(path, flags, mode);
} else {
return __real_open(path, flags);
}
} else {
return -1;
}
}