Skip to content

Commit

Permalink
Make Far2l built on Dragonfly BSD
Browse files Browse the repository at this point in the history
  • Loading branch information
alexax66 committed Apr 8, 2023
1 parent d860dbd commit 1b96d70
Show file tree
Hide file tree
Showing 35 changed files with 73 additions and 65 deletions.
2 changes: 1 addition & 1 deletion FARStdlib/include/all_far.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <signal.h> // SIGxxx
#include <sys/stat.h> // stat
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
# include <malloc.h> // alloc,NULL
#endif
#include <math.h> // sqrt
Expand Down
2 changes: 1 addition & 1 deletion NetRocks/src/Host/HostLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#ifdef __APPLE__
#include <sys/mount.h>
#elif !defined(__FreeBSD__) && !defined(__HAIKU__)
#elif !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__HAIKU__)
#include <sys/statfs.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion NetRocks/src/Protocol/Protocol.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <memory>
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/types.h>
#endif
#include "Erroring.h"
Expand Down
6 changes: 3 additions & 3 deletions WinPort/src/APIFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ extern "C"

#ifndef __linux__
if ((dwFlagsAndAttributes & (FILE_FLAG_WRITE_THROUGH|FILE_FLAG_NO_BUFFERING)) != 0) {
#if defined(__FreeBSD__) || defined(__HAIKU__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__HAIKU__)
fcntl(r, O_DIRECT, 1);
#elif !defined(__CYGWIN__)
fcntl(r, F_NOCACHE, 1);
Expand Down Expand Up @@ -433,7 +433,7 @@ extern "C"
if (fstat(wph->fd, &s) == -1)
return FALSE;

#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__HAIKU__)
int ret = posix_fallocate(wph->fd, 0, (off_t)RequireFileSize);
if (ret == 0)
return TRUE;
Expand Down Expand Up @@ -589,7 +589,7 @@ extern "C"
_attr = FILE_ATTRIBUTE_REPARSE_POINT;
}

#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
if (DereferencedStat().st_flags & UF_HIDDEN) { // chflags hidden FILENAME
_attr|= FILE_ATTRIBUTE_HIDDEN;
}
Expand Down
4 changes: 2 additions & 2 deletions WinPort/src/Backend/TTY/TTYBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# include <termios.h>
# include <linux/kd.h>
# include <linux/keyboard.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/ioctl.h>
# include <sys/kbio.h>
#endif
Expand Down Expand Up @@ -1033,7 +1033,7 @@ DWORD TTYBackend::QueryControlKeys()
}
#endif

#if defined(__FreeBSD__) || defined(__linux__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__linux__)
unsigned long int leds = 0;
if (ioctl(_stdin, KDGETLED, &leds) == 0) {
if (leds & 1) {
Expand Down
4 changes: 2 additions & 2 deletions WinPort/src/Backend/TTY/TTYOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# include <termios.h>
# include <linux/kd.h>
# include <linux/keyboard.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/ioctl.h>
# include <sys/kbio.h>
#endif
Expand Down Expand Up @@ -151,7 +151,7 @@ TTYOutput::TTYOutput(int out, bool far2l_tty)
:
_out(out), _far2l_tty(far2l_tty), _kernel_tty(false)
{
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
unsigned long int leds = 0;
if (ioctl(out, KDGETLED, &leds) == 0) {
// running under linux 'real' TTY, such kind of terminal cannot be dropped due to lost connection etc
Expand Down
4 changes: 2 additions & 2 deletions WinPort/src/Backend/WinPortMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# include <termios.h>
# include <linux/kd.h>
# include <linux/keyboard.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/ioctl.h>
# include <sys/kbio.h>
#endif
Expand Down Expand Up @@ -300,7 +300,7 @@ extern "C" int WinPortMain(const char *full_exe_path, int argc, char **argv, int

InitPalette();

#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
unsigned long int leds = 0;
if (ioctl(0, KDGETLED, &leds) == 0) {
// running under linux 'real' TTY, such kind of terminal cannot be dropped due to lost connection etc
Expand Down
3 changes: 3 additions & 0 deletions WinPort/src/sudo/sudo_askpass_ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <utils.h>
#include <os_call.hpp>
#include <ScopeHelpers.h>
#ifdef __DragonFly__
#include <cstring>
#endif

#include "sudo_askpass_ipc.h"
#include "sudo_private.h"
Expand Down
16 changes: 8 additions & 8 deletions WinPort/src/sudo/sudo_client_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
# include <sys/mount.h>
#elif !defined(__HAIKU__)
# include <sys/statfs.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
#ifndef __FreeBSD__
#if !defined(__FreeBSD__) && !defined(__DragonFly__)
# include <sys/xattr.h>
#endif
#include <map>
Expand All @@ -24,7 +24,7 @@
#include "sudo_private.h"
#include "sudo.h"

#if !defined(__APPLE__) and !defined(__FreeBSD__) && !defined(__CYGWIN__) && !defined(__HAIKU__)
#if !defined(__APPLE__) and !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__CYGWIN__) && !defined(__HAIKU__)
# include <sys/ioctl.h>
# include <linux/fs.h>
#endif
Expand Down Expand Up @@ -727,7 +727,7 @@ extern "C" __attribute__ ((visibility("default"))) char *sdc_getcwd(char *buf, s

extern "C" __attribute__ ((visibility("default"))) ssize_t sdc_flistxattr(int fd, char *namebuf, size_t size)
{
#if defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
return -1;
#elif defined(__APPLE__)
return flistxattr(fd, namebuf, size, 0);
Expand All @@ -738,7 +738,7 @@ extern "C" __attribute__ ((visibility("default"))) ssize_t sdc_flistxattr(int fd

extern "C" __attribute__ ((visibility("default"))) ssize_t sdc_fgetxattr(int fd, const char *name,void *value, size_t size)
{
#if defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
return -1;
#elif defined(__APPLE__)
return fgetxattr(fd, name, value, size, 0, 0);
Expand All @@ -749,7 +749,7 @@ extern "C" __attribute__ ((visibility("default"))) ssize_t sdc_fgetxattr(int fd,

extern "C" __attribute__ ((visibility("default"))) int sdc_fsetxattr(int fd, const char *name, const void *value, size_t size, int flags)
{
#if defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
return -1;
#elif defined(__APPLE__)
return fsetxattr(fd, name, value, size, 0, flags);
Expand All @@ -768,7 +768,7 @@ extern "C" __attribute__ ((visibility("default"))) int sdc_fsetxattr(int fd, con
*flags = 0;
return 0;

#elif defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
struct stat s{};
int r = sdc_stat(path, &s);
if (r == 0) {
Expand Down Expand Up @@ -813,7 +813,7 @@ extern "C" __attribute__ ((visibility("default"))) int sdc_fsetxattr(int fd, con
#else
ClientReconstructCurDir crcd(path);
int r;
# if defined(__APPLE__) || defined(__FreeBSD__)
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
r = chflags(path, flags);
# else
int fd = r = open(path, O_RDONLY);
Expand Down
2 changes: 1 addition & 1 deletion WinPort/src/sudo/sudo_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Sudo

/////////////////////

#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__HAIKU__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__HAIKU__)
# include <sys/ioctl.h>

int bugaware_ioctl_pint(int fd, unsigned long req, unsigned long *v)
Expand Down
8 changes: 4 additions & 4 deletions WinPort/src/sudo/sudo_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
#include <sys/mount.h>
#elif !defined(__HAIKU__)
#include <sys/statfs.h>
Expand All @@ -18,7 +18,7 @@
#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/types.h>
#ifndef __FreeBSD__
#if !defined(__FreeBSD__) && !defined(__DragonFly__)
# include <sys/xattr.h>
#endif
#include <stdexcept>
Expand Down Expand Up @@ -280,7 +280,7 @@ namespace Sudo

static void OnSudoDispatch_FSFlagsGet(BaseTransaction &bt)
{
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__CYGWIN__) && !defined(__HAIKU__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__CYGWIN__) && !defined(__HAIKU__)
std::string path;
bt.RecvStr(path);
int r = -1;
Expand All @@ -307,7 +307,7 @@ namespace Sudo
bt.RecvStr(path);
bt.RecvPOD(flags);

#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
if (chflags(path.c_str(), flags) == 0) {
bt.SendInt(0);
return;
Expand Down
2 changes: 1 addition & 1 deletion WinPort/src/sudo/sudo_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace Sudo
~ClientReconstructCurDir();
};

#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
int bugaware_ioctl_pint(int fd, unsigned long req, unsigned long *v);
#endif

Expand Down
2 changes: 1 addition & 1 deletion WinPort/sudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <sys/statvfs.h>
#ifdef __APPLE__
#include <sys/mount.h>
#elif !defined(__FreeBSD__) && !defined(__HAIKU__)
#elif !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__HAIKU__)
#include <sys/statfs.h>
#endif
#include <dirent.h>
Expand Down
6 changes: 3 additions & 3 deletions far2l/src/base/SafeMMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <time.h>
#include <dlfcn.h>

#if !defined(__FreeBSD__) && !defined(__MUSL__) && !defined(__UCLIBC__) && !defined(__HAIKU__) // todo: pass to linker -lexecinfo under BSD and then may remove this ifndef
#if !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__MUSL__) && !defined(__UCLIBC__) && !defined(__HAIKU__) // todo: pass to linker -lexecinfo under BSD and then may remove this ifndef
# include <execinfo.h>
# define HAS_BACKTRACE
#endif
Expand Down Expand Up @@ -284,7 +284,7 @@ void SafeMMap::Slide(off_t file_offset)
// So for that systems use approach looking most optimal: remap same pages to
// different region of file. At least this should allow VMM to avoid searching
// for free pages as well as reduce syscalls count by avoiding call to munmap().
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
void *new_view = mmap(_view, new_len, _prot, _flags | MAP_FIXED, _fd, file_offset);
#else
void *new_view = mmap(nullptr, new_len, _prot, _flags, _fd, file_offset);
Expand All @@ -294,7 +294,7 @@ void SafeMMap::Slide(off_t file_offset)
}

if (_view != new_view) {
#if !defined(__linux__) && !defined(__FreeBSD__)
#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
fprintf(stderr, "SafeMMap::Slide: _view[%p] != new_view[%p]\n", _view, new_view);
#endif
if (munmap(_view, _len) == -1) {
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/base/farrtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void __cdecl far_qsortex(void *base, size_t num, size_t width,
qsort(base, num, width, QSortExAdapter);
}

#elif defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
struct QSortExAdapterArg
{
int (*__cdecl comp)(const void *, const void *, void *);
Expand Down
5 changes: 5 additions & 0 deletions far2l/src/console/scrsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static wchar_t EggstraSymbol[3][2]=
{0x1F608,0x0000}, // 😈
{0x1F608,0x0000}, // 😈

#elif defined(__DragonFly__)
{0x1F608,0x0000}, // 😈
{0x1F608,0x0000}, // 😈
{0x1F608,0x0000}, // 😈

#else
{0x1F95A,0x0000}, // 🥚
{0x1F95A,0x0000}, // 🥚
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ScopeHelpers.h"
#include <set>
#include <sys/wait.h>
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__DragonFly__)
# include <signal.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion far2l/src/farwinapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/statvfs.h>
#include <fcntl.h>
#include <errno.h>
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
# include <sys/mount.h>
#elif !defined(__HAIKU__)
# include <sys/statfs.h>
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef __GNUC__
#include <cctype>
#include <climits>
#if !defined(__APPLE__) and !defined(__FreeBSD__)
#if !defined(__APPLE__) and !defined(__FreeBSD__) && !defined(__DragonFly__)
#include <malloc.h>
#endif
#endif //__GNUC__
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/mix/FSFileFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void FSFileFlags::SetAppend(bool v)
}
}

#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)

bool FSFileFlags::Hidden() const
{
Expand Down
4 changes: 2 additions & 2 deletions far2l/src/mix/FSFileFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class FSFileFlags
bool Append() const;
void SetAppend(bool v);

#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
bool Hidden() const;
void SetHidden(bool v);
#endif
};

#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
# define FS_FLAGS_CONTAIN_IMMUTABLE(flags) (((flags) & (UF_IMMUTABLE | SF_IMMUTABLE)) != 0)
# define FS_FLAGS_WITHOUT_IMMUTABLE(flags) ((flags) & (~(UF_IMMUTABLE | SF_IMMUTABLE)))
# define FS_FLAGS_WITH_IMMUTABLE(flags) ((flags) | (UF_IMMUTABLE))
Expand Down
6 changes: 3 additions & 3 deletions far2l/src/mix/MountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <fcntl.h>
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__CYGWIN__)
# if defined(__APPLE__) || defined(__FreeBSD__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/param.h>
# include <sys/ucred.h>
# endif
Expand Down Expand Up @@ -268,7 +268,7 @@ MountInfo::MountInfo(bool for_location_menu)
}
}

#elif defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)

int r = getfsstat(nullptr, 0, MNT_NOWAIT);
if (r > 0) {
Expand Down
4 changes: 2 additions & 2 deletions far2l/src/panels/infolist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//# include <sys/sysctl.h>
# include <mach/mach_host.h>
# include <mach/vm_statistics.h>
#elif !defined(__FreeBSD__) && !defined(__HAIKU__)
#elif !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__HAIKU__)
# include <sys/sysinfo.h>
#endif

Expand Down Expand Up @@ -256,7 +256,7 @@ void InfoList::DisplayObject()
}


#elif !defined(__FreeBSD__) && !defined(__HAIKU__)
#elif !defined(__FreeBSD__) && !defined(__DragonFly__) && !defined(__HAIKU__)
struct sysinfo si = {};
if (sysinfo(&si) == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion far2l/src/panels/treelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <sys/stat.h>
#include <sys/statvfs.h>
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__CYGWIN__)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
# include <sys/mount.h>
#elif !defined(__HAIKU__)
# include <sys/statfs.h>
Expand Down
Loading

0 comments on commit 1b96d70

Please sign in to comment.