--- /dev/null
+# $Id$
+
+# autoconf/Make.common.in -*- Makefile -*-
+# release date (man), LSM date, version number/name, current maintainer
+DATE="15 Apr 2004"
+LSMDATE=15Apr04
+VERSION=1.35.0
+VERNAME=bacula-$(VERSION)#
+MAINT=Kern Sibbald#
+MAINTEMAIL=<kern@sibbald.com>#
+WEBMAINT=#
+WEBMAINTEMAIL=#
+WEBPAGE=#
+FTPSITENAME=#
+FTPSITEDIR=#
+#-------------------------------------------------------------------------
+
+SHELL = /bin/sh
+
+# Installation target directories & other installation stuff
+prefix =
+exec_prefix =
+binprefix =
+manprefix =
+sbindir = /sbin
+sysconfdir = /etc/bacula
+scriptdir = /etc/bacula
+mandir = ${prefix}/man/man1
+manext = 1
+
+# Tools & program stuff
+CC = gcc
+CPP = gcc -E
+CXX = g++
+MV = /usr/bin/mv
+RM = /usr/bin/rm
+RMF = /usr/bin/rm -f
+CP = /usr/bin/cp
+SED = /usr/bin/sed
+AWK = /usr/bin/awk
+ECHO = /usr/bin/echo
+CMP = /usr/bin/cmp
+TBL = /usr/bin/tbl
+AR = ar
+RANLIB = ranlib
+INSTALL = /usr/bin/install -c
+# add the -s to the following in PRODUCTION mode
+INSTALL_PROGRAM = /usr/bin/install -c -m 754
+INSTALL_DATA = /usr/bin/install -c -m 644
+INSTALL_SCRIPT = /usr/bin/install -c -m 754
+INSTALL_CONFIG = /usr/bin/install -c -m 640
+
+# Flags & libs
+CFLAGS = -g -O2 -Wall
+CPPFLAGS =
+LDFLAGS = -O
+TTOOL_LDFLAGS =
+DEFS = -DHAVE_WIN32 -DHAVE_MINGW
+LIBS = -lpthread
+DINCLUDE =
+DLIB =
+DB_LIBS =
+
+# Windows (cygwin) flags
+WCFLAGS = -mwindows
+WLDFLAGS = -mwindows
+
+# X Include directory
+#XINC = @XPM_CFLAGS@
+
+# extra libraries needed by X on some systems, X library location
+#XLIB = @XPM_LIBS@ -lX11
+
+# End of common section of the Makefile
+#-------------------------------------------------------------------------
+
+CWEB = @CWEB@
+CTANGLE = $(CWEB)/ctangle
+CWEAVE = $(CWEB)/cweave
+TEXINPUTS = TEXINPUTS=.:$(CWEB):
+
+# FIXME -- These should be found by autoconf
+TEX = tex
+PDFTEX = pdftex
+XDVI = xdvi
+DVIPS = dvips
+
+srcdir = .
+VPATH = .
+.PATH: .
+
+# one up
+basedir = ..
+# top dir
+topdir = ../..
+# this dir relative to top dir
+thisdir = src/lib
+
+
+DEBUG=
+
+GMP_INC=@GMP_INC@
+
+first_rule: all
+dummy:
+
+LIBSRCS = alloc.c attr.c base64.c bsys.c bget_msg.c \
+ bnet.c bnet_server.c \
+ bpipe.c bshm.c btime.c \
+ cram-md5.c crc32.c daemon.c edit.c fnmatch.c \
+ hmac.c idcache.c jcr.c lex.c alist.c dlist.c \
+ md5.c message.c mem_pool.c parse_conf.c \
+ queue.c rwlock.c scan.c serial.c sha1.c \
+ semlock.c signal.c smartall.c tree.c \
+ util.c var.c watchdog.c workq.c timers.c
+
+
+LIBOBJS = alloc.o attr.o base64.o bsys.o bget_msg.o \
+ bnet.o bnet_server.o \
+ bpipe.o bshm.o btime.o \
+ cram-md5.o crc32.o daemon.o edit.o fnmatch.o \
+ hmac.o idcache.o jcr.o lex.o alist.o dlist.o \
+ md5.o message.o mem_pool.o parse_conf.o \
+ queue.o rwlock.o scan.o serial.o sha1.o \
+ semlock.o signal.o smartall.o tree.o \
+ util.o var.o watchdog.o workq.o timers.o
+
+
+
+EXTRAOBJS =
+
+
+.SUFFIXES: .c .o .ch .dvi .pdf .tex .view .w .1
+.PHONY:
+.DONTCARE:
+
+# inference rules
+compat.o: ../win32/compat/compat.cpp
+ $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat \
+ -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -o compat.o ../win32/compat/compat.cpp
+
+.c.o:
+ $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
+
+.cc.o:
+ $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $<
+
+.w.c:
+ $(CTANGLE) $<
+
+.w.tex:
+ $(CWEAVE) $<
+
+.tex.dvi:
+ ( $(TEXINPUTS) ; export TEXINPUTS; $(TEX) $< )
+
+.tex.pdf:
+ ( $(TEXINPUTS) ; export TEXINPUTS; $(PDFTEX) $< )
+
+.dvi.view:
+ $(XDVI) -s 0 $<
+
+#-------------------------------------------------------------------------
+all: Makefile libbac.a
+ @echo "==== Make of lib is good ===="
+ @echo " "
+
+libbac.a: $(LIBOBJS) compat.o
+ $(AR) rc $@ $(LIBOBJS) compat.o
+ $(RANLIB) $@
+
+
+Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
+ cd $(topdir) \
+ && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+rwlock_test:
+ rm -f rwlock.o
+ $(CXX) -DTEST_RWLOCK $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c
+ $(CXX) $(LDFLAGS) -L. -o $@ rwlock.o $(LIBS) $(DLIB) -lbac -lm
+ rm -f rwlock.o
+ $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c
+
+md5sum:
+ rm -f md5.o
+ $(CXX) -DMD5_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c
+ $(CXX) $(LDFLAGS) -L. -o $@ md5.o $(LIBS) $(DLIB) -lbac -lm
+ rm -f md5.o
+ $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c
+
+
+sha1sum:
+ rm -f sha1.o
+ $(CXX) -DSHA1_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c
+ $(CXX) $(LDFLAGS) -L. -o $@ sha1.o $(LIBS) $(DLIB) -lbac -lm
+ rm -f sha1.o
+ $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c
+
+install:
+
+uninstall:
+
+clean:
+ $(RMF) *.a core a.out *.o *.bak *.tex *.pdf *~ *.intpro *.extpro 1 2 3
+ $(RMF) rwlock_test md5sum sha1sum
+
+realclean: clean
+ $(RMF) tags
+
+distclean: realclean
+ if test $(srcdir) = .; then $(MAKE) realclean; fi
+ (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS)
+
+# Semi-automatic generation of dependencies:
+# Use gcc -MM because X11 `makedepend' doesn't work on all systems
+# and it also includes system headers.
+# `semi'-automatic since dependencies are generated at distribution time.
+
+depend:
+ @$(MV) Makefile Makefile.bak
+ @$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile
+ @$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile
+ @$(CXX) -S -M $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $(SQL_INC) *.c >> Makefile
+ @if test -f Makefile ; then \
+ $(RMF) Makefile.bak; \
+ else \
+ $(MV) Makefile.bak Makefile; \
+ echo -e "Something went wrong\n\a"; \
+ fi
+
+# -----------------------------------------------------------------------
+# DO NOT DELETE: nice dependency list follows
\ No newline at end of file
-// -*- Mode: C++ -*-
+// -*- Mode: C++ -*-
// compat.cpp -- compatibilty layer to make bacula-fd run
// natively under windows
//
-// Copyright transferred from Raider Solutions, Inc to
+// Copyright transferred from Raider Solutions, Inc to
// Kern Sibbald and John Walker by express permission.
//
// Copyright (C) 2004 Kern Sibbald and John Walker
-//
+//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
extern DWORD g_platform_id;
// from CYGWIN (should be diff between Jan 1 1601 and Jan 1 1970
+#ifdef HAVE_MINGW
+#define WIN32_FILETIME_ADJUST 0x19DB1DED53E8000UL //Not sure it works
+#else
#define WIN32_FILETIME_ADJUST 0x19DB1DED53E8000I64
+#endif
#define WIN32_FILETIME_SCALE 10000000 // 100ns/second
mstime *= WIN32_FILETIME_SCALE;
mstime += WIN32_FILETIME_ADJUST;
+ #ifdef HAVE_MINGW
+ wintime.dwLowDateTime = (DWORD)(mstime & 0xffffffffUL);
+ #else
wintime.dwLowDateTime = (DWORD)(mstime & 0xffffffffI64);
+ #endif
wintime.dwHighDateTime = (DWORD) ((mstime>>32)& 0xffffffffUL);
}
return (const char *) lpMsgBuf;
}
+#ifndef HAVE_MINGW
+
static int
statDir(const char *file, struct stat *sb)
{
errno = GetLastError();
return -1;
}
-
- if (attr & FILE_ATTRIBUTE_DIRECTORY)
+
+ if (attr & FILE_ATTRIBUTE_DIRECTORY)
return statDir(tmpbuf, sb);
h = CreateFile(tmpbuf, GENERIC_READ,
errno = GetLastError();
goto error;
}
-
+
if (!GetFileInformationByHandle(h, &info)) {
const char *err = errorString();
d_msg(__FILE__, __LINE__, 99,
errno = GetLastError();
goto error;
}
-
+
sb->st_dev = info.dwVolumeSerialNumber;
sb->st_ino = info.nFileIndexHigh;
sb->st_ino <<= 32;
if (!GetFileAttributesEx(file, GetFileExInfoStandard, &data))
return stat2(file, sb);
#endif
-
+
sb->st_mode = 0777; /* start with everything */
if (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
sb->st_mode &= ~(S_IRUSR|S_IRGRP|S_IROTH);
sleep(int sec)
{
Sleep(sec * 1000);
-}
+}
+
+#endif //HAVE_MINGW
int
geteuid(void)
}
+#ifndef HAVE_MINGW
int
strcasecmp(const char *s1, const char *s2)
{
register int ch1, ch2;
-
+
if (s1==s2)
return 0; /* strings are equal if same object. */
else if (!s1)
s1++;
s2++;
} while (ch1 != 0 && tolower(ch1) == tolower(ch2));
-
+
return(ch1 - ch2);
}
+#endif //HAVE_MINGW
int
strncasecmp(const char *s1, const char *s2, int len)
{
register int ch1, ch2;
-
+
if (s1==s2)
return 0; /* strings are equal if same object. */
else if (!s1)
s1++;
s2++;
} while (len-- && ch1 != 0 && tolower(ch1) == tolower(ch2));
-
+
return(ch1 - ch2);
}
_100nsec <<= 32;
_100nsec |= tmp.dwLowDateTime;
_100nsec -= WIN32_FILETIME_ADJUST;
-
+
tv->tv_sec =(long) (_100nsec / 10000000);
tv->tv_usec = (long) ((_100nsec % 10000000)/10);
return 0;
-
+
}
int
return NULL;
}
-
+#ifndef HAVE_MINGW
// implement opendir/readdir/closedir on top of window's API
typedef struct _dir
{
int max_len = strlen(path) + 16;
_dir *rval = NULL;
if (path == NULL) return NULL;
-
+
rval = (_dir *)malloc(sizeof(_dir));
if (rval == NULL) return NULL;
char *tspec = (char *)malloc(max_len);
if (tspec == NULL) goto err1;
-
+
if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) {
// allow path to be 32767 bytes
tspec[0] = '\\';
tspec[2] = '?';
tspec[3] = '\\';
tspec[4] = 0;
- cygwin_conv_to_win32_path(path, tspec+4);
+ cygwin_conv_to_win32_path(path, tspec+4);
} else {
cygwin_conv_to_win32_path(path, tspec);
}
free(rval);
return NULL;
}
-
+
int
closedir(DIR *dirp)
{
dp->valid = FindNextFile(dp->dirh, &dp->data);
return 0;
}
-
+#endif //HAVE_MINGW
int
inet_aton(const char *a, struct in_addr *inp)
{
WORD wVersionRequested = MAKEWORD( 1, 1);
WSADATA wsaData;
-
+
int err = WSAStartup(wVersionRequested, &wsaData);
-
-
+
+
if (err != 0)
{
printf("Can not start Windows Sockets\n");
buf[n] = '\\';
buf[n+1] = 0;
}
-
+
return buf;
}
close_bpipe(b);
#endif
}
-
-BOOL CreateChildProcess(VOID);
-VOID WriteToPipe(VOID);
-VOID ReadFromPipe(VOID);
-VOID ErrorExit(LPTSTR);
-VOID ErrMsg(LPTSTR, BOOL);
-
+
+BOOL CreateChildProcess(VOID);
+VOID WriteToPipe(VOID);
+VOID ReadFromPipe(VOID);
+VOID ErrorExit(LPTSTR);
+VOID ErrMsg(LPTSTR, BOOL);
+
const char *
getArgv0(const char *cmdline)
}
HANDLE
-CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err)
-{
- PROCESS_INFORMATION piProcInfo;
+CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err)
+{
+ PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
- BOOL bFuncRetn = FALSE;
-
- // Set up members of the PROCESS_INFORMATION structure.
-
+ BOOL bFuncRetn = FALSE;
+
+ // Set up members of the PROCESS_INFORMATION structure.
+
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
-
- // Set up members of the STARTUPINFO structure.
-
+
+ // Set up members of the STARTUPINFO structure.
+
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
// setup new process to use supplied handles for stdin,stdout,stderr
siStartInfo.hStdInput = in;
else
siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
-
+
if (out != INVALID_HANDLE_VALUE)
siStartInfo.hStdOutput = out;
else
siStartInfo.hStdError = err;
else
siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
- // Create the child process.
-
+ // Create the child process.
+
char cmdLine[1024];
char exeFile[1024];
// retrive the first compont of the command line which should be the
- // executable
+ // executable
const char *exeName = getArgv0(cmdline);
// check to see if absolute path was passed to us already?
if (exeName[1] != ':'
|| (strchr(cmdline, '/') == NULL
&& strchr(cmdline, '\\') == NULL))
{
- // only command name so perform search of PATH to find
+ // only command name so perform search of PATH to find
char *file;
DWORD rval = SearchPath(NULL,
exeName,
return INVALID_HANDLE_VALUE;
}
- else
+ else
strcpy(exeFile, exeName);
// exeFile now has absolute path to program to execute.
// copy original command line to pass to create process
strcpy(cmdLine, cmdline);
// try to execute program
- bFuncRetn = CreateProcess(exeFile,
- cmdLine, // command line
- NULL, // process security attributes
- NULL, // primary thread security attributes
- TRUE, // handles are inherited
- 0, // creation flags
- NULL, // use parent's environment
- NULL, // use parent's current directory
- &siStartInfo, // STARTUPINFO pointer
+ bFuncRetn = CreateProcess(exeFile,
+ cmdLine, // command line
+ NULL, // process security attributes
+ NULL, // primary thread security attributes
+ TRUE, // handles are inherited
+ 0, // creation flags
+ NULL, // use parent's environment
+ NULL, // use parent's current directory
+ &siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
-
+
if (bFuncRetn == 0) {
ErrorExit("CreateProcess failed\n");
return INVALID_HANDLE_VALUE;
// we don't need a handle on the process primary thread so we close
// this now.
CloseHandle(piProcInfo.hThread);
-
+
return piProcInfo.hProcess;
}
-
+
void
-ErrorExit (LPTSTR lpszMessage)
-{
+ErrorExit (LPTSTR lpszMessage)
+{
d_msg(__FILE__, __LINE__, 0, "%s", lpszMessage);
-}
-
+}
+
/*
typedef struct s_bpipe {
CloseHandle(handle);
}
+#ifndef HAVE_MINGW
BPIPE *
open_bpipe(char *prog, int wait, const char *mode)
{
- HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
- hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup,
+ HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
+ hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup,
hInputFile;
-
- SECURITY_ATTRIBUTES saAttr;
- BOOL fSuccess;
+ SECURITY_ATTRIBUTES saAttr;
+
+ BOOL fSuccess;
- hChildStdinRd = hChildStdinWr = hChildStdinWrDup =
- hChildStdoutRd = hChildStdoutWr = hChildStdoutRdDup =
+ hChildStdinRd = hChildStdinWr = hChildStdinWrDup =
+ hChildStdoutRd = hChildStdoutWr = hChildStdoutRdDup =
hInputFile = INVALID_HANDLE_VALUE;
-
+
BPIPE *bpipe = (BPIPE *)malloc(sizeof(BPIPE));
memset((void *)bpipe, 0, sizeof(BPIPE));
int mode_read = (mode[0] == 'r');
int mode_write = (mode[0] == 'w' || mode[1] == 'w');
-
-
- // Set the bInheritHandle flag so pipe handles are inherited.
-
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
- saAttr.bInheritHandle = TRUE;
- saAttr.lpSecurityDescriptor = NULL;
-
+
+
+ // Set the bInheritHandle flag so pipe handles are inherited.
+
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+ saAttr.bInheritHandle = TRUE;
+ saAttr.lpSecurityDescriptor = NULL;
+
if (mode_read) {
-
- // Create a pipe for the child process's STDOUT.
+
+ // Create a pipe for the child process's STDOUT.
if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) {
ErrorExit("Stdout pipe creation failed\n");
goto cleanup;
}
- // Create noninheritable read handle and close the inheritable read
- // handle.
-
+ // Create noninheritable read handle and close the inheritable read
+ // handle.
+
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
GetCurrentProcess(), &hChildStdoutRdDup , 0,
FALSE,
ErrorExit("DuplicateHandle failed");
goto cleanup;
}
-
+
CloseHandle(hChildStdoutRd);
}
-
+
if (mode_write) {
-
- // Create a pipe for the child process's STDIN.
-
+
+ // Create a pipe for the child process's STDIN.
+
if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) {
ErrorExit("Stdin pipe creation failed\n");
goto cleanup;
}
-
- // Duplicate the write handle to the pipe so it is not inherited.
- fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
+
+ // Duplicate the write handle to the pipe so it is not inherited.
+ fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
GetCurrentProcess(), &hChildStdinWrDup,
- 0,
- FALSE, // not inherited
- DUPLICATE_SAME_ACCESS);
+ 0,
+ FALSE, // not inherited
+ DUPLICATE_SAME_ACCESS);
if (!fSuccess) {
ErrorExit("DuplicateHandle failed");
goto cleanup;
}
-
- CloseHandle(hChildStdinWr);
+
+ CloseHandle(hChildStdinWr);
}
// spawn program with redirected handles as appropriate
bpipe->worker_pid = (pid_t)
hChildStdinRd, // stdin HANDLE
hChildStdoutWr, // stdout HANDLE
hChildStdoutWr);// stderr HANDLE
-
+
if ((HANDLE) bpipe->worker_pid == INVALID_HANDLE_VALUE)
goto cleanup;
-
+
bpipe->wait = wait;
bpipe->worker_stime = time(NULL);
-
+
if (mode_read) {
CloseHandle(hChildStdoutWr); // close our write side so when
// process terminates we can
int wfd = _open_osfhandle((long)hChildStdinWrDup, O_WRONLY);
bpipe->wfd = _fdopen(wfd, "w");
}
-
+
if (wait > 0) {
bpipe->timer_id = start_child_timer(bpipe->worker_pid, wait);
}
-
+
return bpipe;
-
+
cleanup:
-
+
CloseIfValid(hChildStdoutRd);
CloseIfValid(hChildStdoutRdDup);
CloseIfValid(hChildStdinWr);
CloseIfValid(hChildStdinWrDup);
-
+
free((void *) bpipe);
-
+
return NULL;
}
+#endif //HAVE_MINGW
+
int
kill(int pid, int signal)
{
return rval;
}
+#ifndef HAVE_MINGW
+
int
close_bpipe(BPIPE *bpipe)
{
if (bpipe->wait) {
int remaining_wait = bpipe->wait;
- do
+ do
{
DWORD exitCode;
if (!GetExitCodeProcess((HANDLE)bpipe->worker_pid, &exitCode))
{
const char *err = errorString();
rval = GetLastError();
- d_msg(__FILE__, __LINE__, 0,
+ d_msg(__FILE__, __LINE__, 0,
"GetExitCode error %s\n", err);
LocalFree((void *)err);
break;
}
-
+
if (exitCode == STILL_ACTIVE) {
bmicrosleep(1, 0); /* wait one second */
remaining_wait--;
else break;
} while(remaining_wait);
}
-
+
if (bpipe->timer_id) {
stop_child_timer(bpipe->timer_id);
}
- free((void *)bpipe);
+ free((void *)bpipe);
return rval;
}
close_wpipe(BPIPE *bpipe)
{
int stat = 1;
-
+
if (bpipe->wfd) {
fflush(bpipe->wfd);
if (fclose(bpipe->wfd) != 0) {
int rval = SetFileTime(h, NULL, &acc, &mod) ? 0 : -1;
CloseHandle(h);
-
+
return rval;
}
if (flags & O_WRONLY) access = GENERIC_WRITE;
else if (flags & O_RDWR) access = GENERIC_READ|GENERIC_WRITE;
else access = GENERIC_READ;
-
+
if (flags & O_CREAT) create = CREATE_NEW;
else create = OPEN_EXISTING;
-
+
if (flags & O_TRUNC) create = TRUNCATE_EXISTING;
-
+
if (!(flags & O_EXCL))
shareMode = FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE;
-
+
if (flags & O_APPEND)
{
printf("open...APPEND not implemented yet.");
exit(-1);
}
-
+
foo = CreateFile(file, access, shareMode, NULL, create, msflags, NULL);
if (INVALID_HANDLE_VALUE == foo)
return(int) -1;
default:
return -1;
}
-
+
return SetFilePointer((HANDLE)fd, (DWORD)offset, NULL, method);
}
#endif
+
+#endif //HAVE_MINGW
+
+#ifdef HAVE_MINGW
+/* syslog function, added by Nicolas Boichat */
+void closelog() {}
+#endif //HAVE_MINGW
-/* -*- Mode: C -*-
- * compat.h --
+/* -*- Mode: C -*-
+ * compat.h --
*/
-// Copyright transferred from Raider Solutions, Inc to
+// Copyright transferred from Raider Solutions, Inc to
// Kern Sibbald and John Walker by express permission.
//
// Copyright (C) 2004 Kern Sibbald and John Walker
-//
+//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
- *
- *
+/*
+ *
* Author : Christopher S. Hull
* Created On : Fri Jan 30 13:00:51 2004
- * Last Modified By: Christopher S. Hull
- * Last Modified On: Tue Feb 24 11:13:32 2004
+ * Last Modified By: Nicolas Boichat
+ * Last Modified On: Sat Apr 17 19:30:00 2004
* Update Count : 218
* $Id$
*/
#ifndef __COMPAT_H_
#define __COMPAT_H_
+#ifndef HAVE_MINGW
#define __STDC__ 1
+#endif
#include <stdio.h>
#include <basetsd.h>
#include <fcntl.h>
#include <io.h>
+#if defined HAVE_MINGW
+#include <stdint.h>
+#include <sys/stat.h>
+#endif
#include "getopt.h"
+#ifdef HAVE_MINGW
+#define HAVE_WIN32 1
+#else
#ifdef HAVE_CYGWIN
#error should not be used under cygwin...
#else
#define HAVE_WIN32 1
-#endif
+#endif //HAVE_CYGWIN
+#endif //HAVE_MINGW
typedef UINT64 u_int64_t;
typedef UINT64 uint64_t;
typedef INT64 int64_t;
typedef signed short int16_t;
typedef long time_t;
#if __STDC__
+#ifndef HAVE_MINGW
typedef _dev_t dev_t;
typedef __int64 ino_t;
typedef __int64 off_t; /* STDC=1 means we can define this */
+#endif
#else
typedef long _off_t; /* must be same as sys/types.h */
#endif
typedef signed char int8_t;
+#ifndef HAVE_MINGW
typedef int BOOL;
#define bool BOOL
+#endif
typedef double float64_t;
typedef UINT32 u_int32_t;
typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
+#ifndef HAVE_MINGW
#undef uint32_t
+#endif
void sleep(int);
typedef UINT32 key_t;
+
+#ifdef HAVE_MINGW
+#ifndef uid_t
+typedef UINT32 uid_t;
+typedef UINT32 gid_t;
+#endif
+#else
typedef UINT32 uid_t;
typedef UINT32 gid_t;
typedef UINT32 mode_t;
typedef INT64 ssize_t;
-
-typedef void DIR;
-
-
struct dirent {
uint64_t d_ino;
uint32_t d_off;
char d_name[256];
};
+#endif //HAVE_MINGW
+
+typedef void DIR;
+
#ifndef __cplusplus
#ifndef true
#define true 1
#define ETIMEDOUT 55
+#ifndef HAVE_MINGW
struct stat
{
_dev_t st_dev;
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
#define S_IXUSR S_IEXEC
+#endif //HAVE_MINGW
#define S_IRGRP 000040
#define S_IWGRP 000020
#define S_ISGID 002000
#define S_ISVTX 001000
-
+#ifndef HAVE_MINGW
#define S_ISREG(x) (((x) & S_IFREG) == S_IFREG)
#define S_ISDIR(x) (((x) & S_IFDIR) == S_IFDIR)
#define S_ISCHR(x) 0
#define S_ISBLK(x) 0
#define S_ISFIFO(x) 0
+#endif //HAVE_MINGW
#define S_ISSOCK(x) 0
#define S_ISLNK(x) 0
int lchown(const char *, uid_t uid, gid_t gid);
int chown(const char *, uid_t uid, gid_t gid);
int chmod(const char *, mode_t mode);
+#ifndef HAVE_MINGW
int utime(const char *filename, struct utimbuf *buf);
int open(const char *, int, int);
-off_t lseek(int, off_t, int);
ssize_t read(int fd, void *, size_t nbytes);
ssize_t write(int fd, const void *, size_t nbytes);
int close(int fd);
+#endif //HAVE_MINGW
+off_t lseek(int, off_t, int);
int inet_aton(const char *cp, struct in_addr *inp);
int kill(int pid, int signo);
int pipe(int []);
#define HAVE_OLD_SOCKOPT
-
+#ifndef HAVE_MINGW
#define vsnprintf __vsnprintf
int __vsnprintf(char *s, size_t count, const char *format, va_list args);
#define sprintf __sprintf
int __sprintf(char *str, const char *fmt, ...);
-
+#endif //HAVE_MINGW
int readdir(unsigned int fd, struct dirent *dirp, unsigned int count);
int nanosleep(const struct timespec*, struct timespec *);
int geteuid();
+
+#ifndef HAVE_MINGW
DIR *opendir(const char *name);
int closedir(DIR *dir);
+#endif //HAVE_MINGW
struct passwd {
char *foo;
struct passwd *getpwuid(uid_t);
struct group *getgrgid(uid_t);
+#ifndef HAVE_MINGW
#define R_OK 04
#define W_OK 02
-
+#endif //HAVE_MINGW
struct sigaction {
int sa_flags;
#define mkdir(p, m) _mkdir(p)
#define chdir win32_chdir
+#ifndef HAVE_MINGW
int stat(const char *, struct stat *);
+#endif //HAVE_MINGW
int syslog(int, const char *, const char *);
#define LOG_DAEMON 0
#define LOG_ERR 0
+#ifndef HAVE_MINGW
#ifdef __cplusplus
#define access _access
extern "C" _CRTIMP int __cdecl _access(const char *, int);
int execvp(const char *, char *[]);
extern "C" void * __cdecl _alloca(size_t);
#endif
+#endif //HAVE_MINGW
#define getpid _getpid
int WSA_Init(void);
+#ifdef HAVE_MINGW
+void closelog();
+#endif //HAVE_MINGW
+
#endif /* __COMPAT_H_ */