8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Added LSB compliance (#28)

This commit is contained in:
Dmitry Starodubov 2016-05-25 15:14:01 +03:00 committed by Alexander Peshkov
parent 6cef0ffa19
commit c3722be6de
52 changed files with 494 additions and 185 deletions

View File

@ -58,6 +58,12 @@ else
Process := master_process
endif
ifeq ($(LSB_FLG),Y)
GCC=/opt/lsb/bin/lsbcc
else
GCC=gcc
endif
.PHONY: master_process cross_process firebird Debug Release extern
all: firebird
@ -123,18 +129,18 @@ $(GEN_ROOT)/Make.Version : $(SRC_ROOT)/misc/writeBuildNum.sh
#
extern:
$(MAKE) -C $(ROOT)/extern/btyacc
$(MAKE) -C $(ROOT)/extern/cloop TARGET=release WITH_FPC=0 BUILD_DIR=$(TMP_ROOT)/cloop OUT_DIR=$(GEN_ROOT)/$(TARGET)/cloop
$(MAKE) -C $(ROOT)/extern/btyacc CC="$(CC)" CXX="$(CXX)"
$(MAKE) -C $(ROOT)/extern/cloop TARGET=release WITH_FPC=0 BUILD_DIR=$(TMP_ROOT)/cloop OUT_DIR=$(GEN_ROOT)/$(TARGET)/cloop CC="$(CC)" CXX="$(CXX)"
ifeq ($(TOMBUILD_FLG),Y)
$(MAKE) -C $(ROOT)/extern/libtommath -f makefile.shared
CFLAGS="$(CFLAGS)" $(MAKE) -C $(ROOT)/extern/libtommath -f makefile.shared GCC=$(GCC)
ln -sf $(TOMMATH_SO).$(TOMMATH_VER) $(LIB)
ln -sf $(TOMMATH_SO) $(LIB)
endif
ifeq ($(STD_EDITLINE),false)
ifeq ($(EDITLINE_FLG),Y)
$(MAKE) -f $(GEN_ROOT)/Makefile.extern.editline
$(MAKE) -f $(GEN_ROOT)/Makefile.extern.editline CC="$(CC)" CXX="$(CXX)"
endif
endif
@ -567,7 +573,7 @@ $(FIREBIRD_MSG): $(BUILD_FILE) msg.timestamp
$(CHMOD_6) $@
$(BUILD_FILE): $(BUILD_Objects) $(COMMON_LIB)
$(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS)
$(EXE_LINK) $(EXE_LINK_OPTIONS) $(LSB_UNDEF) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS)
gbak_files: $(GBAK_FILES)

View File

@ -134,7 +134,7 @@ $(EXAMPLES_DEST)/isql$(EXEC_EXT):
$(LN) $(ISQL) $(EXAMPLES_DEST)/isql$(EXEC_EXT)
$(EXAMPLES_DEST)/empbuild$(EXEC_EXT): $(EMPBLD_Objects) $(COMMON_LIB)
$(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ -L$(LIB) $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS)
$(EXE_LINK) $(EXE_LINK_OPTIONS) $(LSB_UNDEF) $^ -o $@ -L$(LIB) $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS)
$(EXAMPLES_DEST)/empbuild.c: $(EXAMPLES_DEST)/empbuild.fdb $(EXAMPLES_DEST)/empbuild.e

View File

@ -106,7 +106,7 @@ AllObjects += $(CA_Objects)
crypt_app: $(CRYPT_APP)
$(CRYPT_APP): $(CA_Objects)
$(EXE_LINK) $^ -o $@ $(FIREBIRD_LIBRARY_LINK)
$(EXE_LINK) $(LSB_UNDEF) $^ -o $@ $(FIREBIRD_LIBRARY_LINK)
include $(ROOT)/gen/make.shared.targets

View File

@ -133,6 +133,11 @@ CAS_OPTIONS=@CAS_OPTIONS@
# multiple-precision integer library
MATHLIB=@MATHLIB@
LSB_FLG=@LSB_FLG@
ifeq ($(LSB_FLG), Y)
LSB_UNDEF=-Wl,--allow-shlib-undefined
endif
# switch to make sed edit files inplace
INLINE_EDIT_SED:= -i
@ -162,6 +167,9 @@ CC = @CC@
CXX = @CXX@
LD = @CXX@
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
# LINKER COMMANDS
LIB_LINK = $(CXX) $(GLOB_OPTIONS) $(CXXFLAGS)

View File

@ -38,6 +38,10 @@ ifeq ($(TOMBUILD_FLG),Y)
WFLAGS += -I$(TOMMATH_INC)
endif
ifeq ($(LSB_FLG),Y)
WFLAGS += -DLSB_BUILD
endif
ifeq ($(TARGET),Release)
WFLAGS += $(PROD_FLAGS)
else

View File

@ -555,6 +555,26 @@ if test "x$enable_rpath" != "xno" || test "x$enable_rpath" = "x" ; then
AC_SUBST(USE_RPATH, 1)
fi
LSB_FLG=N
AC_ARG_ENABLE(lsb-build,
[ --enable-lsb-build build LSB-compliant binaries (default=no)],
[case "$enableval" in
yes) LSB_FLG=Y;;
no) LSB_FLG=N;;
*) AC_MSG_ERROR(bad value '${enableval}' for --enable-lsb-build);;
esac])
AC_SUBST(LSB_FLG)
if test "$LSB_FLG" = "Y"; then
CFLAGS="$CFLAGS --lsb-besteffort --lsb-shared-libs=fbclient:ib_util:tommath --lsb-target-version=4.1"
CXXFLAGS="$CXXFLAGS --lsb-besteffort --lsb-shared-libs=fbclient:ib_util:tommath --lsb-target-version=4.1"
AC_SUBST(TOMBUILD, Y)
AC_PATH_PROG(CC, lsbcc, "", [$PATH$PATH_SEPARATOR/opt/lsb/bin$PATH_SEPARATOR])
AC_PATH_PROG(CXX, lsbc++, "", [$PATH$PATH_SEPARATOR/opt/lsb/bin$PATH_SEPARATOR])
if test "x$CC" = "x" || test "x$CXX" = "x" ; then
AC_MSG_ERROR(Can not find LSB compilers in /opt/lsb/bin)
fi
fi
AC_ARG_WITH(editline,
[ --with-editline support fancy command line editing],
[case "$withval" in
@ -767,8 +787,11 @@ fi
dnl check for ICU presence
AC_CHECK_HEADER(unicode/ucnv.h,,AC_MSG_ERROR(ICU support not found - please install development ICU package))
if test "$LSB_FLG" = "N"; then
dnl setting ICU_OK here is done to only avoid default action
AC_CHECK_LIB(icuuc, main, ICU_OK=yes, AC_MSG_ERROR(ICU support not found - please install development ICU package))
fi
dnl check for tommath presence
if test "$TOMBUILD" = "Y"; then

View File

@ -4,8 +4,8 @@ WITH_FPC := 1
TARGET := release
CC := gcc
CXX := g++
CC := $(CC)
CXX := $(CXX)
LD := $(CXX)
SRC_DIR := src

View File

@ -106,6 +106,11 @@ static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *);
#define MAXEXTRAS 30
// LSB compliance
#ifndef NBBY
#define NBBY CHAR_BIT
#endif
static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~";
static const wchar_t char_glob[] = L"*?[#";

View File

@ -2,8 +2,15 @@
#
#Tom St Denis
VERSION=0:41
VERSION_SO=0.41
LIBNAME_SO=libtommath.so
LIBNAME_SO_0=$(LIBNAME_SO).0
CC = libtool --mode=compile --tag=CC gcc
ifndef GCC
GCC=gcc
endif
CC = libtool --mode=compile --tag=CC $(GCC)
CFLAGS += -I./ -Wall -W -Wshadow -Wsign-compare
@ -83,7 +90,9 @@ bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o
objs: $(OBJECTS)
$(LIBNAME): $(OBJECTS)
libtool --mode=link --tag=CC gcc *.lo -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION)
$(GCC) -shared -fPIC -DPIC $(CFLAGS) $(addprefix .libs/, $(OBJECTS)) -Wl,-soname -Wl,$(LIBNAME_SO_0) -o .libs/$(LIBNAME_SO_0).$(VERSION_SO)
ln -sf $(LIBNAME_SO_0).$(VERSION_SO) .libs/$(LIBNAME_SO_0)
ln -sf $(LIBNAME_SO_0).$(VERSION_SO) .libs/$(LIBNAME_SO)
install: $(LIBNAME)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
@ -92,11 +101,11 @@ install: $(LIBNAME)
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
test: $(LIBNAME) demo/demo.o
gcc $(CFLAGS) -c demo/demo.c -o demo/demo.o
libtool --mode=link gcc -o test demo/demo.o $(LIBNAME_S)
$(GCC) $(CFLAGS) -c demo/demo.c -o demo/demo.o
libtool --mode=link $(GCC) -o test demo/demo.o $(LIBNAME_S)
mtest: test
cd mtest ; gcc $(CFLAGS) mtest.c -o mtest
cd mtest ; $(GCC) $(CFLAGS) mtest.c -o mtest
timing: $(LIBNAME)
gcc $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME_S) -o ltmtest
$(GCC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME_S) -o ltmtest

View File

@ -2122,7 +2122,7 @@ static gbak_action open_files(const TEXT* file1,
else
SetTapePosition(fil->fil_fd, TAPE_REWIND, 0, 0, 0, FALSE);
#else
lseek(fil->fil_fd, 0, SEEK_SET);
fb_io::lseek(fil->fil_fd, 0, SEEK_SET);
#endif
tdgbl->file_desc = fil->fil_fd;
tdgbl->gbl_sw_files = fil->fil_next;
@ -2381,10 +2381,10 @@ void close_platf(DESC file)
#define O_ACCMODE 3
#endif
off_t fileSize = lseek(file, 0, SEEK_CUR);
off_t fileSize = fb_io::lseek(file, 0, SEEK_CUR);
if (fileSize != (off_t)(-1))
{
FB_UNUSED(ftruncate(file, fileSize));
FB_UNUSED(fb_io::ftruncate(file, fileSize));
}
}

View File

@ -90,7 +90,7 @@ bool ScanDir::next()
if (!dir)
return false;
while ((data = readdir (dir)))
while ((data = fb_io::readdir (dir)))
{
if (match (pattern.c_str(), data->d_name))
return true;
@ -150,12 +150,12 @@ bool ScanDir::isDirectory()
{
#if defined(_WIN32)
return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
#elif defined(HAVE_STRUCT_DIRENT_D_TYPE)
#elif defined(HAVE_STRUCT_DIRENT_D_TYPE) && !defined(LSB_BUILD)
return (data->d_type == DT_DIR);
#else
struct stat buf;
struct STAT buf;
if (stat (getFilePath(), &buf))
if (fb_io::stat(getFilePath(), &buf))
return false;
return S_ISDIR (buf.st_mode);

View File

@ -201,7 +201,7 @@ void Thread::kill(Handle& thread)
ThreadId Thread::getId()
{
#if defined(LINUX) && !defined(ANDROID)
#if defined(LINUX) && !defined(ANDROID) && !defined(LSB_BUILD)
return syscall(SYS_gettid);
#else
return pthread_self();

View File

@ -211,7 +211,7 @@ void TempFile::init(const PathName& directory, const PathName& prefix)
filename += NAME_PATTERN;
#ifdef HAVE_MKSTEMP
handle = (IPTR) mkstemp(filename.begin());
handle = (IPTR) fb_io::mkstemp(filename.begin());
#else
if (!mktemp(filename.begin()))
{
@ -275,7 +275,7 @@ void TempFile::seek(const offset_t offset)
system_error::raise("SetFilePointer");
}
#else
const off_t seek_result = ::lseek(handle, (off_t) offset, SEEK_SET);
const off_t seek_result = fb_io::lseek(handle, (off_t) offset, SEEK_SET);
if (seek_result == (off_t) -1)
{
system_error::raise("lseek");

View File

@ -2215,13 +2215,13 @@ void* MemPool::allocRaw(size_t size) throw (OOM_EXCEPTION)
#ifdef MAP_ANONYMOUS
void* result = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
void* result = fb_io::mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#else // MAP_ANONYMOUS
if (dev_zero_fd < 0)
dev_zero_fd = os_utils::open("/dev/zero", O_RDWR);
void* result = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero_fd, 0);
void* result = fb_io::mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero_fd, 0);
#endif // MAP_ANONYMOUS

View File

@ -65,6 +65,19 @@
#include <unistd.h>
#endif
#ifndef WIN_NT
#include <dirent.h>
#include <sys/mman.h>
#include <sys/resource.h>
#else
#include <io.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 200112L && !defined(WIN_NT)
// above check is generally true. However, we use pthreads on some platforms
// where _POSIX_THREADS is defined to "1" or not even defined at all!
@ -869,8 +882,252 @@ void GDS_breakpoint(int);
/* The default lseek offset type. Changed from nothing to (off_t) to correctly support 64 bit IO */
#ifndef LSEEK_OFFSET_CAST
#ifdef LSB_BUILD
#define LSEEK_OFFSET_CAST (loff_t)
#else
#define LSEEK_OFFSET_CAST (off_t)
#endif
#endif
// LSB uses 32bit IO functions by default
#ifdef LSB_BUILD
#define off_t loff_t
#define fpos_t fpos64_t
#define dirent dirent64
#define rlimit rlimit64
#define STAT stat64
#define FSTAT fstat64
#define LSTAT lstat64
#define FLOCK flock64
#else
#define STAT stat
#define FSTAT fstat
#define LSTAT lstat
#define LSTAT lstat
#define FLOCK flock
#endif
#ifdef WIN_NT
#define mode_t int
#endif
namespace fb_io {
inline int open(const char* pathname, int flags, mode_t mode = 0666) {
int rc;
do {
#ifdef LSB_BUILD
rc = open64(pathname, flags, mode);
#else
rc = ::open(pathname, flags, mode);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline FILE *fopen(const char *path, const char *mode) {
FILE* rc = NULL;
do {
#ifdef LSB_BUILD
rc = fopen64(path, mode);
#else
rc = ::fopen(path, mode);
#endif
} while (rc == NULL && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline off_t lseek(int fd, off_t offset, int whence) {
off_t rc;
do {
#ifdef LSB_BUILD
rc = lseek64(fd, offset, whence);
#else
rc = ::lseek(fd, offset, whence);
#endif
} while (rc == (off_t) -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int stat(const char *path, struct STAT *buf) {
int rc;
do {
#ifdef LSB_BUILD
rc = stat64(path, buf);
#else
rc = ::stat(path, buf);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int fstat(int fd, struct STAT *buf) {
int rc;
do {
#ifdef LSB_BUILD
rc = fstat64(fd, buf);
#else
rc = ::fstat(fd, buf);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int fgetpos(FILE *stream, fpos_t *pos) {
int rc;
do {
#ifdef LSB_BUILD
rc = fgetpos64(stream, pos);
#else
rc = ::fgetpos(stream, pos);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int fsetpos(FILE *stream, const fpos_t *pos) {
int rc;
do {
#ifdef LSB_BUILD
rc = fsetpos64(stream, pos);
#else
rc = ::fsetpos(stream, pos);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
#ifndef WIN_NT
inline int lockf(int fd, int cmd, off_t len) {
int rc;
do {
#ifdef LSB_BUILD
rc = lockf64(fd, cmd, len);
#else
rc = ::lockf(fd, cmd, len);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int mkstemp(char *__template) {
int rc;
do {
#ifdef LSB_BUILD
rc = mkstemp64(__template);
#else
rc = ::mkstemp(__template);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
// Don't check EINTR because it's done by caller
return
#ifdef LSB_BUILD
pread64(fd, buf, count, offset);
#else
::pread(fd, buf, count, offset);
#endif
}
inline ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
// Don't check EINTR because it's done by caller
return
#ifdef LSB_BUILD
pwrite64(fd, buf, count, offset);
#else
::pwrite(fd, buf, count, offset);
#endif
}
inline struct dirent *readdir(DIR *dirp) {
struct dirent* rc;
do {
#ifdef LSB_BUILD
rc = readdir64(dirp);
#else
rc = ::readdir(dirp);
#endif
} while (rc == NULL && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset) {
void* rc;
do {
#ifdef LSB_BUILD
rc = mmap64(addr, length, prot, flags, fd, offset);
#else
rc = ::mmap(addr, length, prot, flags, fd, offset);
#endif
} while (rc == MAP_FAILED && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int ftruncate(int fd, off_t length) {
int rc;
do {
#ifdef LSB_BUILD
rc = ftruncate64(fd, length);
#else
rc = ::ftruncate(fd, length);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int lstat(const char *path, struct STAT *buf) {
int rc;
do {
#ifdef LSB_BUILD
rc = lstat64(path, buf);
#else
rc = ::lstat(path, buf);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int posix_fadvise(int fd, off_t offset, off_t len, int advice) {
int rc;
do {
#ifdef LSB_BUILD
rc = posix_fadvise64(fd, offset, len, advice);
#else
rc = ::posix_fadvise(fd, offset, len, advice);
#endif
} while (rc != 0 && SYSCALL_INTERRUPTED(rc));
return rc;
}
inline int getrlimit(int resource, struct rlimit *rlim) {
int rc;
do {
#ifdef LSB_BUILD
rc = getrlimit64(resource, rlim);
#else
rc = ::getrlimit(resource, rlim);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
inline int setrlimit(int resource, const struct rlimit *rlim) {
int rc;
do {
#ifdef LSB_BUILD
rc = setrlimit64(resource, rlim);
#else
rc = ::setrlimit(resource, rlim);
#endif
} while (rc == -1 && SYSCALL_INTERRUPTED(errno));
return rc;
}
#endif // WIN_NT
} // namespace fb_io
#define STRINGIZE_AUX(x) #x
#define STRINGIZE(x) STRINGIZE_AUX(x)

View File

@ -83,8 +83,8 @@ Firebird::PathName ConfigCache::getFileName()
time_t ConfigCache::File::getTime()
{
struct stat st;
if (stat(fileName.c_str(), &st) != 0)
struct STAT st;
if (fb_io::stat(fileName.c_str(), &st) != 0)
{
if (errno == ENOENT)
{

View File

@ -255,8 +255,8 @@ namespace {
DevNode getNode(const char* name)
{
struct stat statistics;
if (stat(name, &statistics) != 0)
struct STAT statistics;
if (fb_io::stat(name, &statistics) != 0)
{
if (errno == ENOENT)
{
@ -272,8 +272,8 @@ namespace {
DevNode getNode(int fd)
{
struct stat statistics;
if (fstat(fd, &statistics) != 0)
struct STAT statistics;
if (fb_io::fstat(fd, &statistics) != 0)
{
system_call_failed::raise("stat");
}
@ -447,7 +447,7 @@ int FileLock::setlock(const LockMode mode)
#ifdef USE_FCNTL
// Take lock on a file
struct flock lock;
struct FLOCK lock;
lock.l_type = shared ? F_RDLCK : F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = lStart;
@ -545,7 +545,7 @@ void FileLock::unlock()
}
#ifdef USE_FCNTL
struct flock lock;
struct FLOCK lock;
lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET;
lock.l_start = lStart;
@ -719,7 +719,7 @@ namespace {
return;
}
FB_UNUSED(ftruncate(fdSem, sizeof(*this)));
FB_UNUSED(fb_io::ftruncate(fdSem, sizeof(*this)));
for (int i = 0; i < N_SETS; ++i)
{
@ -1839,7 +1839,7 @@ SharedMemoryBase::SharedMemoryBase(const TEXT* filename, ULONG length, IpcObject
public:
static void init(int fd)
{
void* sTab = mmap(0, sizeof(SemTable), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
void* sTab = fb_io::mmap(0, sizeof(SemTable), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if ((U_IPTR) sTab == (U_IPTR) -1)
{
system_call_failed::raise("mmap");
@ -1878,8 +1878,8 @@ SharedMemoryBase::SharedMemoryBase(const TEXT* filename, ULONG length, IpcObject
if (length == 0)
{
// Get and use the existing length of the shared segment
struct stat file_stat;
if (fstat(mainLock->getFd(), &file_stat) == -1)
struct STAT file_stat;
if (fb_io::fstat(mainLock->getFd(), &file_stat) == -1)
{
system_call_failed::raise("fstat");
}
@ -1893,7 +1893,7 @@ SharedMemoryBase::SharedMemoryBase(const TEXT* filename, ULONG length, IpcObject
}
// map file to memory
void* const address = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), 0);
void* const address = fb_io::mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), 0);
if ((U_IPTR) address == (U_IPTR) -1)
{
system_call_failed::raise("mmap", errno);
@ -1958,7 +1958,7 @@ SharedMemoryBase::SharedMemoryBase(const TEXT* filename, ULONG length, IpcObject
if (mainLock->setlock(&statusVector, FileLock::FLM_TRY_EXCLUSIVE))
{
if (trunc_flag)
FB_UNUSED(ftruncate(mainLock->getFd(), length));
FB_UNUSED(fb_io::ftruncate(mainLock->getFd(), length));
if (callback->initialize(this, true))
{
@ -2470,7 +2470,7 @@ UCHAR* SharedMemoryBase::mapObject(CheckStatusWrapper* statusVector, ULONG objec
const ULONG end = FB_ALIGN(object_offset + object_length, page_size);
const ULONG length = end - start;
UCHAR* address = (UCHAR*) mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), start);
UCHAR* address = (UCHAR*) fb_io::mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), start);
if ((U_IPTR) address == (U_IPTR) -1)
{
@ -3085,10 +3085,10 @@ bool SharedMemoryBase::remapFile(CheckStatusWrapper* statusVector, ULONG new_len
}
if (flag)
FB_UNUSED(ftruncate(mainLock->getFd(), new_length));
FB_UNUSED(fb_io::ftruncate(mainLock->getFd(), new_length));
MemoryHeader* const address = (MemoryHeader*)
mmap(0, new_length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), 0);
fb_io::mmap(0, new_length, PROT_READ | PROT_WRITE, MAP_SHARED, mainLock->getFd(), 0);
if ((U_IPTR) address == (U_IPTR) -1)
{
error(statusVector, "mmap() failed", errno);
@ -3290,8 +3290,8 @@ static SLONG create_semaphores(CheckStatusWrapper* statusVector, SLONG key, int
// We want to limit access to semaphores, created here
// Reasonable access rights to them - exactly like security database has
const char* secDb = Config::getDefaultConfig()->getSecurityDatabase();
struct stat st;
if (stat(secDb, &st) == 0)
struct STAT st;
if (fb_io::stat(secDb, &st) == 0)
{
union semun arg;
semid_ds ds;

View File

@ -55,8 +55,8 @@ private:
bool ModuleLoader::isLoadableModule(const Firebird::PathName& module)
{
struct stat sb;
if (-1 == stat(module.c_str(), &sb))
struct STAT sb;
if (-1 == fb_io::stat(module.c_str(), &sb))
return false;
if ( ! (sb.st_mode & S_IFREG) ) // Make sure it is a plain file
return false;

View File

@ -37,7 +37,6 @@
#ifdef WIN_NT
#include <sys/stat.h>
#define mode_t int
#define DEFAULT_OPEN_MODE (_S_IREAD | _S_IWRITE)
#else
#define DEFAULT_OPEN_MODE (0666)

View File

@ -52,8 +52,8 @@ private:
bool ModuleLoader::isLoadableModule(const Firebird::PathName& module)
{
struct stat sb;
if (-1 == stat(module.c_str(), &sb))
struct STAT sb;
if (-1 == fb_io::stat(module.c_str(), &sb))
return false;
if ( ! (sb.st_mode & S_IFREG) ) // Make sure it is a plain file
return false;

View File

@ -73,6 +73,11 @@
#include <sys/signal.h>
#endif
#if defined(LSB_BUILD) && LSB_BUILD < 50
#define O_CLOEXEC 02000000
#endif
using namespace Firebird;
namespace os_utils
@ -140,13 +145,9 @@ void createLockDirectory(const char* pathname)
{
if (access(pathname, R_OK | W_OK | X_OK) == 0)
{
struct stat st;
while (stat(pathname, &st) != 0)
struct STAT st;
if (fb_io::stat(pathname, &st) != 0)
{
if (SYSCALL_INTERRUPTED(errno))
{
continue;
}
system_call_failed::raise("stat");
}
@ -197,12 +198,10 @@ int openCreateSharedFile(const char* pathname, int flags)
// Malicious user can create a symlink with this name pointing to say
// security2.fdb and when the lock file is created the file will be damaged.
struct stat st;
struct STAT st;
int rc;
do {
rc = fstat(fd, &st);
} while (fd != 0 && SYSCALL_INTERRUPTED(errno));
rc = fb_io::fstat(fd, &st);
if (rc != 0)
{
@ -265,15 +264,11 @@ void setCloseOnExec(int fd)
int open(const char* pathname, int flags, mode_t mode)
{
int fd;
do {
fd = ::open(pathname, flags | O_CLOEXEC, mode);
} while (fd < 0 && SYSCALL_INTERRUPTED(errno));
fd = fb_io::open(pathname, flags | O_CLOEXEC, mode);
if (fd < 0 && errno == EINVAL) // probably O_CLOEXEC not accepted
{
do {
fd = ::open(pathname, flags | O_CLOEXEC, mode);
} while (fd < 0 && SYSCALL_INTERRUPTED(errno));
fd = fb_io::open(pathname, flags | O_CLOEXEC, mode);
}
setCloseOnExec(fd);
@ -282,13 +277,13 @@ int open(const char* pathname, int flags, mode_t mode)
FILE* fopen(const char* pathname, const char* mode)
{
FILE* f = ::fopen(pathname, mode); // TODO: use open + fdopen to avoid races
FILE* f = fb_io::fopen(pathname, mode); // TODO: use open + fdopen to avoid races
if (f)
setCloseOnExec(fileno(f));
return f;
}
static void makeUniqueFileId(const struct stat& statistics, UCharBuffer& id)
static void makeUniqueFileId(const struct STAT& statistics, UCharBuffer& id)
{
const size_t len1 = sizeof(statistics.st_dev);
const size_t len2 = sizeof(statistics.st_ino);
@ -303,11 +298,9 @@ static void makeUniqueFileId(const struct stat& statistics, UCharBuffer& id)
void getUniqueFileId(int fd, UCharBuffer& id)
{
struct stat statistics;
while (fstat(fd, &statistics) != 0)
struct STAT statistics;
if (fb_io::fstat(fd, &statistics) != 0)
{
if (errno == EINTR)
continue;
system_call_failed::raise("fstat");
}
@ -317,12 +310,9 @@ void getUniqueFileId(int fd, UCharBuffer& id)
void getUniqueFileId(const char* name, UCharBuffer& id)
{
struct stat statistics;
while (stat(name, &statistics) != 0)
struct STAT statistics;
if (fb_io::stat(name, &statistics) != 0)
{
if (errno == EINTR)
continue;
id.clear();
return;
}

View File

@ -85,7 +85,7 @@ const PosixDirItr& PosixDirItr::operator++()
{
if (done)
return *this;
struct dirent *ent = readdir(dir);
struct dirent *ent = fb_io::readdir(dir);
if (ent == NULL)
{
done = true;
@ -180,10 +180,10 @@ bool PathUtils::isRelative(const Firebird::PathName& path)
bool PathUtils::isSymLink(const Firebird::PathName& path)
{
struct stat st, lst;
if (stat(path.c_str(), &st) != 0)
struct STAT st, lst;
if (fb_io::stat(path.c_str(), &st) != 0)
return false;
if (lstat(path.c_str(), &lst) != 0)
if (fb_io::lstat(path.c_str(), &lst) != 0)
return false;
return st.st_ino != lst.st_ino;
}

View File

@ -240,7 +240,7 @@ void createLockDirectory(const char* pathname)
// open (or create if missing) and set appropriate access rights
int openCreateSharedFile(const char* pathname, int flags)
{
int rc = ::open(pathname, flags | O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
int rc = open(pathname, flags | O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
if (rc < 0)
{
(Firebird::Arg::Gds(isc_io_error) << "open" << pathname << Firebird::Arg::Gds(isc_io_open_err)

View File

@ -403,7 +403,7 @@ int main(int argc, char* argv[])
{
strcpy(spare_file_name, file_name);
if (file_rename(spare_file_name, ext_tab->in, NULL) &&
(input_file = fopen(spare_file_name, FOPEN_READ_TYPE)))
(input_file = fb_io::fopen(spare_file_name, FOPEN_READ_TYPE)))
{
file_name = spare_file_name;
break;
@ -432,11 +432,11 @@ int main(int argc, char* argv[])
while (ext_tab->ext_language != gpreGlob.sw_language)
ext_tab++;
const bool renamed = file_rename(spare_file_name, ext_tab->in, NULL);
if (renamed && (input_file = fopen(spare_file_name, FOPEN_READ_TYPE)))
if (renamed && (input_file = fb_io::fopen(spare_file_name, FOPEN_READ_TYPE)))
{
file_name = spare_file_name;
}
else if (!(input_file = fopen(file_name, FOPEN_READ_TYPE)))
else if (!(input_file = fb_io::fopen(file_name, FOPEN_READ_TYPE)))
{
if (renamed) {
fprintf(stderr, "gpre: can't open %s or %s\n", file_name, spare_file_name);
@ -828,7 +828,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "gpre: output file %s would duplicate input\n", out_file_name);
CPR_exit(FINI_ERROR);
}
if ((gpreGlob.out_file = fopen(out_file_name, FOPEN_WRITE_TYPE)) == NULL)
if ((gpreGlob.out_file = fb_io::fopen(out_file_name, FOPEN_WRITE_TYPE)) == NULL)
{
fprintf(stderr, "gpre: can't open output file %s\n", out_file_name);
CPR_exit(FINI_ERROR);
@ -1312,7 +1312,7 @@ static SLONG compile_module( SLONG start_position, const TEXT* base_directory)
const Firebird::PathName filename = Firebird::TempFile::create(SCRATCH);
strcpy(trace_file_name, filename.c_str());
trace_file = fopen(trace_file_name, "w+b");
trace_file = fb_io::fopen(trace_file_name, "w+b");
#ifdef UNIX
unlink(trace_file_name);
#endif

View File

@ -115,7 +115,7 @@ void InputDevices::indev::getPos(fpos_t* out) const
{
fb_assert(out);
fb_assert(indev_fpointer);
fgetpos(indev_fpointer, out);
fb_io::fgetpos(indev_fpointer, out);
}
// Restore a previously stored reading position held in the parameter.
@ -125,9 +125,9 @@ void InputDevices::indev::setPos(const fpos_t* in)
fb_assert(indev_fpointer);
#ifdef SFIO
// hack to fix bad sfio header
fsetpos(indev_fpointer, const_cast<fpos_t*>(in));
fb_io::fsetpos(indev_fpointer, const_cast<fpos_t*>(in));
#else
fsetpos(indev_fpointer, in);
fb_io::fsetpos(indev_fpointer, in);
#endif
}

View File

@ -3533,7 +3533,7 @@ static processing_state copy_table(TEXT* source,
const bool domain_flag = otherdb[0];
const Firebird::PathName ftmp = TempFile::create(SCRATCH);
isqlGlob.Out = fopen(ftmp.c_str(), "w+b");
isqlGlob.Out = fb_io::fopen(ftmp.c_str(), "w+b");
if (!isqlGlob.Out)
{
// If we can't open a temp file then bail
@ -4153,7 +4153,7 @@ static processing_state edit(const TEXT* const* cmd)
{
TEXT path[MAXPATHLEN];
strip_quotes(file, path);
FILE* fp = fopen(path, "r");
FILE* fp = fb_io::fopen(path, "r");
if (fp)
{
// Push the current ifp on the indev
@ -4185,7 +4185,7 @@ static processing_state edit(const TEXT* const* cmd)
// File used to edit sessions
const Firebird::PathName filename = TempFile::create(SCRATCH);
const char* Tmpfile = filename.c_str();
FILE* f = fopen(Tmpfile, "w+"); // It was w+b
FILE* f = fb_io::fopen(Tmpfile, "w+"); // It was w+b
if (f)
{
Ofp.init(f, Tmpfile, Tmpfile);
@ -4204,7 +4204,7 @@ static processing_state edit(const TEXT* const* cmd)
Ofp.close();
PathName tmpfile = Ofp.fileName(false);
gds__edit(tmpfile.c_str(), 0);
Ofp.init(fopen(tmpfile.c_str(), "r+"), tmpfile.c_str(), tmpfile.c_str()); // We don't check for failure.
Ofp.init(fb_io::fopen(tmpfile.c_str(), "r+"), tmpfile.c_str(), tmpfile.c_str()); // We don't check for failure.
Filelist->Ifp().init(Ofp);
Input_file = true;
getColumn = -1;
@ -6270,7 +6270,7 @@ static processing_state newinput(const TEXT* infile)
// the linked list before discarding the current Ifp.
// Filelist is a global pointing to base of list.
FILE* fp = fopen(file.c_str(), "r");
FILE* fp = fb_io::fopen(file.c_str(), "r");
if (fp)
{
Filelist->insertIfp();
@ -6310,7 +6310,7 @@ static processing_state newoutput(const TEXT* outfile)
TEXT path[MAXPATHLEN];
strip_quotes(outfile, path);
outfile = path;
FILE* fp = fopen(outfile, "a");
FILE* fp = fb_io::fopen(outfile, "a");
if (fp)
{
if (isqlGlob.Out && isqlGlob.Out != stdout)

View File

@ -72,6 +72,9 @@ __int64 __cdecl _ftelli64(FILE*);
#ifdef WIN_NT
#define FTELL64 _ftelli64
#define FSEEK64 _fseeki64
#elif defined(LSB_BUILD)
#define FTELL64 ftello64
#define FSEEK64 fseeko64
#else
#define FTELL64 ftello
#define FSEEK64 fseeko
@ -186,8 +189,8 @@ double EXT_cardinality(thread_db* tdbb, jrd_rel* relation)
struct __stat64 statistics;
if (!_fstat64(_fileno(file->ext_ifi), &statistics))
#else
struct stat statistics;
if (!fstat(fileno(file->ext_ifi), &statistics))
struct STAT statistics;
if (!fb_io::fstat(fileno(file->ext_ifi), &statistics))
#endif
{
file_size = statistics.st_size;

View File

@ -280,14 +280,13 @@ void BackupManager::beginBackup(thread_db* tdbb)
// adjust difference file access rights to make it match main DB ones
if (diff_file && geteuid() == 0)
{
struct stat st;
struct STAT st;
PageSpace* pageSpace = database->dbb_page_manager.findPageSpace(DB_PAGE_SPACE);
const char* func = NULL;
while (!func && fstat(pageSpace->file->fil_desc, &st) != 0)
if (fb_io::fstat(pageSpace->file->fil_desc, &st) != 0)
{
if (errno != EINTR)
func = "fstat";
func = "fstat";
}
while (!func && fchown(diff_file->fil_desc, st.st_uid, st.st_gid) != 0)

View File

@ -104,6 +104,10 @@ using namespace Firebird;
#define O_BINARY 0
#endif
#if !defined(O_DIRECT) && defined(LSB_BUILD)
#define O_DIRECT 00040000
#endif
// please undefine FCNTL_BROKEN for operating systems,
// that can successfully change BOTH O_DIRECT and O_SYNC using fcntl()
@ -260,7 +264,7 @@ jrd_file* PIO_create(thread_db* tdbb, const PathName& file_name,
#endif
}
// posix_fadvise(desc, 0, 0, POSIX_FADV_RANDOM);
// fb_io::posix_fadvise(desc, 0, 0, POSIX_FADV_RANDOM);
// File open succeeded. Now expand the file name.
@ -472,8 +476,8 @@ ULONG PIO_get_number_of_pages(const jrd_file* file, const USHORT pagesize)
return (0);
}
struct stat statistics;
if (fstat(file->fil_desc, &statistics)) {
struct STAT statistics;
if (fb_io::fstat(file->fil_desc, &statistics)) {
unix_error("fstat", file, isc_io_access_err);
}
@ -649,8 +653,8 @@ jrd_file* PIO_open(thread_db* tdbb,
else if (geteuid() == 0)
{
// root has too many rights - therefore artificially check for readonly file
struct stat st;
if (fstat(desc, &st) == 0)
struct STAT st;
if (fb_io::fstat(desc, &st) == 0)
{
readOnly = ((st.st_mode & 0222) == 0); // nobody has write permissions
}
@ -670,7 +674,7 @@ jrd_file* PIO_open(thread_db* tdbb,
const bool shareMode = dbb->dbb_config->getServerMode() != MODE_SUPER;
lockDatabaseFile(desc, shareMode || readOnly, false, file_name.c_str(), isc_io_open_err);
// posix_fadvise(desc, 0, 0, POSIX_FADV_RANDOM);
// fb_io::posix_fadvise(desc, 0, 0, POSIX_FADV_RANDOM);
#ifdef SUPPORT_RAW_DEVICES
// At this point the file has successfully been opened in either RW or RO
@ -741,7 +745,7 @@ bool PIO_read(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,
}
}
// posix_fadvise(file->desc, offset, size, POSIX_FADV_NOREUSE);
// fb_io::posix_fadvise(file->desc, offset, size, POSIX_FADV_NOREUSE);
return true;
}
@ -782,7 +786,7 @@ bool PIO_write(thread_db* tdbb, jrd_file* file, BufferDesc* bdb, Ods::pag* page,
}
// posix_fadvise(file->desc, offset, size, POSIX_FADV_DONTNEED);
// fb_io::posix_fadvise(file->desc, offset, size, POSIX_FADV_DONTNEED);
return true;
}
@ -938,7 +942,7 @@ static void lockDatabaseFile(int& desc, const bool share, const bool temporary,
do
{
#ifndef HAVE_FLOCK
struct flock lck;
struct FLOCK lck;
lck.l_type = shared ? F_RDLCK : F_WRLCK;
lck.l_whence = SEEK_SET;
lck.l_start = 0;
@ -1112,9 +1116,9 @@ bool PIO_on_raw_device(const PathName& file_name)
* Checks if the supplied file name is a special file
*
**************************************/
struct stat s;
struct STAT s;
return (stat(file_name.c_str(), &s) == 0 && (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode)));
return (fb_io::stat(file_name.c_str(), &s) == 0 && (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode)));
}
@ -1145,7 +1149,7 @@ static bool raw_devices_validate_database(int desc, const PathName& file_name)
for (int i = 0; i < IO_RETRY; i++)
{
if (lseek(desc, LSEEK_OFFSET_CAST 0, 0) == (off_t) -1)
if (fb_io::lseek(desc, LSEEK_OFFSET_CAST 0, 0) == (off_t) -1)
{
ERR_post(Arg::Gds(isc_io_error) << Arg::Str("lseek") << Arg::Str(file_name) <<
Arg::Gds(isc_io_read_err) << Arg::Unix(errno));
@ -1167,7 +1171,7 @@ static bool raw_devices_validate_database(int desc, const PathName& file_name)
read_finished:
// Rewind file pointer
if (lseek(desc, LSEEK_OFFSET_CAST 0, 0) == (off_t) -1)
if (fb_io::lseek(desc, LSEEK_OFFSET_CAST 0, 0) == (off_t) -1)
{
ERR_post(Arg::Gds(isc_io_error) << Arg::Str("lseek") << Arg::Str(file_name) <<
Arg::Gds(isc_io_read_err) << Arg::Unix(errno));

View File

@ -335,7 +335,7 @@ void ConfigStorage::addSession(TraceSession& session)
session.ses_flags |= trs_active;
time(&session.ses_start);
const long pos1 = lseek(m_cfg_file, 0, SEEK_END);
const long pos1 = fb_io::lseek(m_cfg_file, 0, SEEK_END);
if (pos1 < 0)
{
const char* fn = m_sharedMemory->getHeader()->cfg_file_name;
@ -359,7 +359,7 @@ void ConfigStorage::addSession(TraceSession& session)
}
putItem(tagEnd, 0, NULL);
// const long pos2 = lseek(m_cfg_file, 0, SEEK_END);
// const long pos2 = fb_io::lseek(m_cfg_file, 0, SEEK_END);
// m_sharedMemory->getHeader()->used_space += pos2 - pos1;
}
@ -439,7 +439,7 @@ bool ConfigStorage::getNextSession(TraceSession& session)
}
else
{
if (lseek(m_cfg_file, len, SEEK_CUR) < 0)
if (fb_io::lseek(m_cfg_file, len, SEEK_CUR) < 0)
checkFileError(m_sharedMemory->getHeader()->cfg_file_name, "lseek", isc_io_read_err);
}
}
@ -473,7 +473,7 @@ void ConfigStorage::removeSession(ULONG id)
// warning C4146: unary minus operator applied to unsigned type, result still unsigned
// but we need a negative offset here.
const long local_len = len;
if (lseek(m_cfg_file, -local_len, SEEK_CUR) < 0)
if (fb_io::lseek(m_cfg_file, -local_len, SEEK_CUR) < 0)
checkFileError(m_sharedMemory->getHeader()->cfg_file_name, "lseek", isc_io_read_err);
if (write(m_cfg_file, &currID, len) != len)
@ -484,7 +484,7 @@ void ConfigStorage::removeSession(ULONG id)
}
else
{
if (lseek(m_cfg_file, len, SEEK_CUR) < 0)
if (fb_io::lseek(m_cfg_file, len, SEEK_CUR) < 0)
checkFileError(m_sharedMemory->getHeader()->cfg_file_name, "lseek", isc_io_read_err);
}
}
@ -495,7 +495,7 @@ void ConfigStorage::restart()
{
checkDirty();
if (lseek(m_cfg_file, 0, SEEK_SET) < 0)
if (fb_io::lseek(m_cfg_file, 0, SEEK_SET) < 0)
checkFileError(m_sharedMemory->getHeader()->cfg_file_name, "lseek", isc_io_read_err);
}
@ -542,7 +542,7 @@ void ConfigStorage::updateSession(TraceSession& session)
}
else if (len)
{
if (lseek(m_cfg_file, len, SEEK_CUR) < 0)
if (fb_io::lseek(m_cfg_file, len, SEEK_CUR) < 0)
checkFileError(m_sharedMemory->getHeader()->cfg_file_name, "lseek", isc_io_read_err);
}
}

View File

@ -140,7 +140,7 @@ FB_SIZE_T TraceLog::read(void* buf, FB_SIZE_T size)
if (reads == 0)
{
// EOF reached, check the reason
const off_t len = lseek(m_fileHandle, 0, SEEK_CUR);
const off_t len = fb_io::lseek(m_fileHandle, 0, SEEK_CUR);
if (len == -1)
system_call_failed::raise("lseek", errno);

View File

@ -533,8 +533,8 @@ int CLIB_ROUTINE main( int argc, char *argv[])
memcpy(p, &file_info.nFileIndexLow, len3);
CloseHandle(h);
#else
struct stat statistics;
if (stat(db_name.c_str(), &statistics) == -1)
struct STAT statistics;
if (fb_io::stat(db_name.c_str(), &statistics) == -1)
{
FPRINTF(outfile, "Unable to open the database file.\n");
exit(FINI_OK);
@ -681,15 +681,15 @@ int CLIB_ROUTINE main( int argc, char *argv[])
}
else if (lock_file)
{
const int fd = open(filename.c_str(), O_RDONLY | O_BINARY);
const int fd = fb_io::open(filename.c_str(), O_RDONLY | O_BINARY);
if (fd == -1)
{
FPRINTF(outfile, "Unable to open lock file.\n");
exit(FINI_OK);
}
struct stat file_stat;
if (fstat(fd, &file_stat) == -1)
struct STAT file_stat;
if (fb_io::fstat(fd, &file_stat) == -1)
{
close(fd);
FPRINTF(outfile, "Unable to retrieve lock file size.\n");
@ -747,7 +747,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
Firebird::PathName extName;
extName.printf("%s.ext%d", filename.c_str(), extent);
const int fd = open(extName.c_str(), O_RDONLY | O_BINARY);
const int fd = fb_io::open(extName.c_str(), O_RDONLY | O_BINARY);
if (fd == -1)
{
FPRINTF(outfile, "Unable to open lock file extent number %d, file %s.\n",

View File

@ -68,7 +68,7 @@ static const char* genFtnPasDirectory = NULL;
static void check_open(FILE*& f, const char* name, const char* tmp, const char* mode)
{
f = fopen(tmp, mode);
f = fb_io::fopen(tmp, mode);
if (!f)
{
fprintf(stderr, "CODES: Unable to open %s in filemode %s for %s\n",

View File

@ -336,7 +336,7 @@ static USHORT do_msgs( const TEXT* filename, const TEXT* locale, bool sw_warning
// Open output file
global_file = open(filename, O_WRONLY | O_CREAT | O_BINARY, 0666);
global_file = fb_io::open(filename, O_WRONLY | O_CREAT | O_BINARY, 0666);
if (global_file == -1)
{
printf("Can't open %s\n", filename);
@ -448,7 +448,7 @@ static USHORT do_msgs( const TEXT* filename, const TEXT* locale, bool sw_warning
// Re-write header record and finish
lseek(global_file, LSEEK_OFFSET_CAST 0, 0);
fb_io::lseek(global_file, LSEEK_OFFSET_CAST 0, 0);
FB_UNUSED(write(global_file, &header, sizeof(header)));
close(global_file);
global_file = -1;

View File

@ -69,7 +69,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
bool sw_bad;
FILE *ind_jrd, *ind_msg, *ind_loc;
ISC_TIMESTAMP date_jrd, date_msg, date_loc;
struct stat file_stat;
struct STAT file_stat;
strcpy(db_file, "msg.fdb");
@ -108,9 +108,9 @@ int CLIB_ROUTINE main( int argc, char *argv[])
flag_jrd = flag_msg = true;
if (ind_jrd = fopen(INCLUDE_INDICATOR, "r"))
if (ind_jrd = fb_io::fopen(INCLUDE_INDICATOR, "r"))
{
if (!fstat(fileno(ind_jrd), &file_stat))
if (!fb_io::fstat(fileno(ind_jrd), &file_stat))
{
isc_encode_date(localtime(&file_stat.st_mtime), (ISC_QUAD*) &date_jrd);
flag_jrd = false;
@ -118,9 +118,9 @@ int CLIB_ROUTINE main( int argc, char *argv[])
fclose(ind_jrd);
}
if (ind_msg = fopen(MESSAGE_INDICATOR, "r"))
if (ind_msg = fb_io::fopen(MESSAGE_INDICATOR, "r"))
{
if (!fstat(fileno(ind_msg), &file_stat))
if (!fb_io::fstat(fileno(ind_msg), &file_stat))
{
isc_encode_date(localtime(&file_stat.st_mtime), (ISC_QUAD*) &date_msg);
flag_msg = false;
@ -131,9 +131,9 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (do_locales)
{
flag_loc = true;
if (ind_loc = fopen(LOCALE_INDICATOR, "r"))
if (ind_loc = fb_io::fopen(LOCALE_INDICATOR, "r"))
{
if (!fstat(fileno(ind_loc), &file_stat))
if (!fb_io::fstat(fileno(ind_loc), &file_stat))
{
isc_encode_date(localtime(&file_stat.st_mtime), (ISC_QUAD*) &date_loc);
flag_loc = false;
@ -179,7 +179,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (flag_jrd)
{
if (ind_jrd = fopen(INCLUDE_INDICATOR, "w"))
if (ind_jrd = fb_io::fopen(INCLUDE_INDICATOR, "w"))
{
fputc(' ', ind_jrd);
fclose(ind_jrd);
@ -188,7 +188,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (flag_msg)
{
if (ind_msg = fopen(MESSAGE_INDICATOR, "w"))
if (ind_msg = fb_io::fopen(MESSAGE_INDICATOR, "w"))
{
fputc(' ', ind_msg);
fclose(ind_msg);
@ -197,7 +197,7 @@ int CLIB_ROUTINE main( int argc, char *argv[])
if (flag_loc)
{
if (ind_loc = fopen(LOCALE_INDICATOR, "w"))
if (ind_loc = fb_io::fopen(LOCALE_INDICATOR, "w"))
{
fputc(' ', ind_loc);
fclose(ind_loc);

View File

@ -221,7 +221,7 @@ static void gen( const char* language, const char* filename)
FOR X IN TEMPLATES WITH X.LANGUAGE EQ language
if (!filename)
filename = FILE;
if (!(output = fopen(filename, "w")))
if (!(output = fb_io::fopen(filename, "w")))
{
perror(FILE);
return;

View File

@ -297,7 +297,7 @@ FILE* EXEC_open_output(qli_nod* node)
if (!node->nod_arg[e_out_pipe])
{
FILE* out_file = fopen(filename, FOPEN_WRITE_TYPE);
FILE* out_file = fb_io::fopen(filename, FOPEN_WRITE_TYPE);
if (out_file)
return out_file;

View File

@ -168,7 +168,7 @@ void LEX_edit(SLONG start, SLONG stop)
*
**************************************/
const Firebird::PathName filename = TempFile::create(SCRATCH);
FILE* scratch = fopen(filename.c_str(), "w+b");
FILE* scratch = fb_io::fopen(filename.c_str(), "w+b");
if (!scratch)
IBERROR(61); // Msg 61 couldn't open scratch file
@ -517,7 +517,7 @@ void LEX_init()
**************************************/
const Firebird::PathName filename = TempFile::create(SCRATCH);
strcpy(trace_file_name, filename.c_str());
trace_file = fopen(trace_file_name, "w+b");
trace_file = fb_io::fopen(trace_file_name, "w+b");
#ifdef UNIX
unlink(trace_file_name);
#endif
@ -631,12 +631,12 @@ bool LEX_push_file(const TEXT* filename, const bool error_flag)
* if the error flag is set, otherwise return quietly.
*
**************************************/
FILE *file = fopen(filename, FOPEN_INPUT_TYPE);
FILE *file = fb_io::fopen(filename, FOPEN_INPUT_TYPE);
if (!file)
{
TEXT buffer[64];
sprintf(buffer, "%s.com", filename);
if (!(file = fopen(buffer, FOPEN_INPUT_TYPE)))
if (!(file = fb_io::fopen(buffer, FOPEN_INPUT_TYPE)))
{
if (error_flag)
ERRQ_msg_put(67, filename);

View File

@ -179,8 +179,8 @@ int CLIB_ROUTINE main( int argc, char** argv)
// It's very easy to detect that we are spawned - just check fd 0 to be a socket.
const int channel = 0;
struct stat stat0;
if (fstat(channel, &stat0) == 0 && S_ISSOCK(stat0.st_mode))
struct STAT stat0;
if (fb_io::fstat(channel, &stat0) == 0 && S_ISSOCK(stat0.st_mode))
{
// classic server mode
classic = true;
@ -507,12 +507,12 @@ static void raiseLimit(int resource)
{
struct rlimit lim;
if (getrlimit(resource, &lim) == 0)
if (fb_io::getrlimit(resource, &lim) == 0)
{
if (lim.rlim_cur != lim.rlim_max)
{
lim.rlim_cur = lim.rlim_max;
if (setrlimit(resource, &lim) != 0)
if (fb_io::setrlimit(resource, &lim) != 0)
{
gds__log("setrlimit() failed, errno=%d", errno);
}

View File

@ -652,7 +652,7 @@ public:
system_call_failed::raise("open");
}
struct flock lock;
struct FLOCK lock;
lock.l_type = F_WRLCK;
lock.l_whence = 0;
lock.l_start = 0;
@ -671,7 +671,7 @@ public:
{
if (fd != -1)
{
struct flock lock;
struct FLOCK lock;
lock.l_type = F_UNLCK;
lock.l_whence = 0;
lock.l_start = 0;

View File

@ -48,6 +48,8 @@
#include "../jrd/ods.h"
#include "../jrd/perf.h"
using namespace syscall_io;
#ifndef HAVE_TIMES
static time_t times(struct tms*);
#endif
@ -108,7 +110,7 @@ void main( int argc, char **argv)
}
SLONG reads = 0, writes = 0;
trace = fopen("trace.log", "r");
trace = fb_io::fopen("trace.log", "r");
page_size = 1024;
SLONG sequence = 0;
@ -352,7 +354,7 @@ static PAG db_read( SLONG page_number)
if (!global_buffer)
global_buffer = (pag*) malloc(page_size);
if (lseek (file, offset, 0) == -1)
if (fb_io::lseek (file, offset, 0) == -1)
db_error(errno);
if (read(file, global_buffer, page_size) == -1)

View File

@ -142,7 +142,7 @@ bool putFileFromArgument(char**& av, ClumpletWriter& spb, unsigned int tag)
if (! *av)
return false;
FILE* const file = fopen(*av, "rb");
FILE* const file = fb_io::fopen(*av, "rb");
if (!file) {
(Arg::Gds(isc_fbsvcmgr_fp_open) << *av << Arg::OsError()).raise();
}

View File

@ -115,7 +115,7 @@ void TraceSvcUtil::startSession(TraceSession& session, bool /*interactive*/)
try
{
const char* fileName = session.ses_config.c_str();
file = fopen(fileName, "rb");
file = fb_io::fopen(fileName, "rb");
if (!file)
{
(Arg::Gds(isc_io_error) << Arg::Str("fopen") << Arg::Str(fileName) <<

View File

@ -2018,7 +2018,7 @@ static const pag* db_read( SLONG page_number, bool ok_enc)
page_number -= fil->fil_min_page - fil->fil_fudge;
const FB_UINT64 offset = ((FB_UINT64) page_number) * ((FB_UINT64) tddba->page_size);
if (lseek (fil->fil_desc, offset, 0) == -1)
if (fb_io::lseek (fil->fil_desc, offset, 0) == -1)
{
tddba->uSvc->setServiceStatus(GSTAT_MSG_FAC, 30, SafeArg());
// msg 30: Can't read a database page

View File

@ -200,7 +200,7 @@ int CLIB_ROUTINE main( int argc, char **argv)
if (pidfilename)
{
FILE *pf = fopen(pidfilename, "w");
FILE *pf = fb_io::fopen(pidfilename, "w");
if (pf)
{
fprintf(pf, "%d", child_pid);

View File

@ -249,7 +249,7 @@ int UTIL_ex_lock(const TEXT* file)
Firebird::PathName expanded_filename = fb_utils::getPrefix(Firebird::IConfigManager::DIR_GUARD, file);
// file fd for the opened and locked file
int fd_file = open(expanded_filename.c_str(), O_RDWR | O_CREAT, 0660);
int fd_file = fb_io::open(expanded_filename.c_str(), O_RDWR | O_CREAT, 0660);
if (fd_file == -1)
{
fprintf(stderr, "Could not open %s for write\n", expanded_filename.c_str());
@ -260,7 +260,7 @@ int UTIL_ex_lock(const TEXT* file)
#ifndef HAVE_FLOCK
// get an exclusive lock on the GUARD file without blocking on the call
struct flock lock;
struct FLOCK lock;
lock.l_type = F_WRLCK;
lock.l_whence = 0;
lock.l_start = 0;
@ -294,7 +294,7 @@ void UTIL_ex_unlock( int fd_file)
#ifndef HAVE_FLOCK
struct flock lock;
struct FLOCK lock;
// get an exclusive lock on the GUARD file with a block
lock.l_type = F_UNLCK;

View File

@ -201,7 +201,7 @@ namespace
#ifdef HAVE_POSIX_FADVISE
int fb_fadvise(int fd, off_t offset, off_t len, int advice)
{
int rc = posix_fadvise(fd, offset, len, advice);
int rc = fb_io::posix_fadvise(fd, offset, len, advice);
if (rc < 0)
{
@ -440,7 +440,7 @@ void NBackup::seek_file(FILE_HANDLE &file, SINT64 pos)
return;
}
#else
if (lseek(file, pos, SEEK_SET) != (off_t) -1)
if (fb_io::lseek(file, pos, SEEK_SET) != (off_t) -1)
return;
#endif
@ -466,7 +466,7 @@ void NBackup::open_database_write(bool exclusive)
O_EXCL | O_RDWR | O_LARGEFILE :
O_RDWR | O_LARGEFILE;
dbase = open(dbname.c_str(), flags);
dbase = fb_io::open(dbname.c_str(), flags);
if (dbase >= 0)
return;
#endif

View File

@ -78,7 +78,7 @@ SINT64 PluginLogWriter::seekToEnd()
#ifdef WIN_NT
SINT64 nFileLen = _lseeki64(m_fileHandle, 0, SEEK_END);
#else
off_t nFileLen = lseek(m_fileHandle, 0, SEEK_END);
off_t nFileLen = fb_io::lseek(m_fileHandle, 0, SEEK_END);
#endif
if (nFileLen < 0)
@ -104,7 +104,7 @@ void PluginLogWriter::reopen()
);
m_fileHandle = _open_osfhandle((intptr_t) hFile, 0);
#else
m_fileHandle = ::open(m_fileName.c_str(), O_CREAT | O_APPEND | O_RDWR, S_IREAD | S_IWRITE);
m_fileHandle = fb_io::open(m_fileName.c_str(), O_CREAT | O_APPEND | O_RDWR, S_IREAD | S_IWRITE);
#endif
if (m_fileHandle < 0)

View File

@ -68,7 +68,7 @@ void FileObject::open(int flags, int pflags)
if (flags & fo_excl)
oflags |= O_EXCL;
file = ::open(filename.c_str(), oflags, pflags);
file = fb_io::open(filename.c_str(), oflags, pflags);
open_mutex.leave();
if (file < 0)
@ -87,8 +87,8 @@ FileObject::~FileObject()
FB_UINT64 FileObject::size()
{
off_t nFileLen = 0;
struct stat file_stat;
if (!fstat(file, &file_stat))
struct STAT file_stat;
if (!fb_io::fstat(file, &file_stat))
nFileLen = file_stat.st_size;
else
fatal_exception::raiseFmt("IO error (%d) file stat: %s", errno, filename.c_str());
@ -176,7 +176,7 @@ SINT64 FileObject::seek(SINT64 newOffset, SeekOrigin origin)
break;
}
off_t result = lseek(file, newOffset, moveMethod);
off_t result = fb_io::lseek(file, newOffset, moveMethod);
if (result == (off_t) -1)
{

View File

@ -228,7 +228,7 @@ int main( int argc, char *argv[])
gdbb->tdbb_database->dbb_pcontrol->pgc_pip = 1;
if (ascii_out)
dbg_file = fopen(ascii_out, "w");
dbg_file = fb_io::fopen(ascii_out, "w");
if (sw_print && rbdb && header)
write_headers(dbg_file, rbdb, p_lower_bound, p_upper_bound);
@ -349,7 +349,7 @@ void RBDB_open( rbdb* rbdb)
* Open a database file.
*
**************************************/
if ((rbdb->rbdb_file.fil_file = open(rbdb->rbdb_file.fil_name, O_RDWR, 0)) == -1)
if ((rbdb->rbdb_file.fil_file = fb_io::open(rbdb->rbdb_file.fil_name, O_RDWR, 0)) == -1)
{
db_error(errno);
}
@ -371,7 +371,7 @@ PAG RBDB_read(rbdb* rbdb, SLONG page_number)
int file = rbdb->rbdb_file.fil_file;
const FB_UINT64 offset = ((FB_UINT64) page_number) * ((FB_UINT64) rbdb->rbdb_page_size);
if (lseek (file, offset, 0) == -1)
if (fb_io::lseek (file, offset, 0) == -1)
db_error(errno);
SSHORT length = rbdb->rbdb_page_size;
@ -407,7 +407,7 @@ void RBDB_write( rbdb* rbdb, PAG page, SLONG page_number)
int fd = rbdb->rbdb_file.fil_file;
const FB_UINT64 offset = ((FB_UINT64) page_number) * ((FB_UINT64) page_size);
if (lseek (fd, offset, 0) == -1)
if (fb_io::lseek (fd, offset, 0) == -1)
db_error(errno);
if (write(fd, page, page_size) == -1)
db_error(errno);

View File

@ -36,10 +36,11 @@
//#define ISC_TIME_SECONDS_PRECISION_SCALE -4
#include "firebird.h"
#include "firebird/Interface.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "firebird/Interface.h"
#include "../common/gdsassert.h"
#include "../common/file_params.h"
#include "../common/msg_encode.h"
@ -78,7 +79,6 @@
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
@ -1192,7 +1192,7 @@ void API_ROUTINE gds__log(const TEXT* text, ...)
#ifdef HAVE_FLOCK
if (flock(fileno(file), LOCK_EX))
#else
if (lockf(fileno(file), F_LOCK, 0))
if (fb_io::lockf(fileno(file), F_LOCK, 0))
#endif
{
// give up
@ -1511,7 +1511,7 @@ SSHORT API_ROUTINE gds__msg_lookup(void* handle,
status = 0;
for (USHORT n = 1; !status; n++)
{
if (lseek(messageL->msg_file, LSEEK_OFFSET_CAST position, 0) < 0)
if (fb_io::lseek(messageL->msg_file, LSEEK_OFFSET_CAST position, 0) < 0)
status = -6;
else if (read(messageL->msg_file, messageL->msg_bucket, messageL->msg_bucket_size) < 0)
status = -7;

View File

@ -1554,8 +1554,8 @@ int API_ROUTINE gds__edit(const TEXT* file_name, USHORT /*type*/)
editor = "Notepad";
#endif
struct stat before;
stat(file_name, &before);
struct STAT before;
fb_io::stat(file_name, &before);
// The path of the editor + the path of the file + quotes + one space.
// We aren't using quotes around the editor for now.
TEXT buffer[MAXPATHLEN * 2 + 5];
@ -1563,8 +1563,8 @@ int API_ROUTINE gds__edit(const TEXT* file_name, USHORT /*type*/)
FB_UNUSED(system(buffer));
struct stat after;
stat(file_name, &after);
struct STAT after;
fb_io::stat(file_name, &after);
return (before.st_mtime != after.st_mtime || before.st_size != after.st_size);
}