Skip to content

Commit eff74ed

Browse files
sibnickNikolay Tolstokulakov
authored and
Nikolay Tolstokulakov
committed
netbsd patch
1 parent 42625ce commit eff74ed

9 files changed

+73
-2
lines changed

osmodel.mak

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ ifeq (,$(OS))
1212
ifeq (FreeBSD,$(uname_S))
1313
OS:=freebsd
1414
endif
15+
ifeq (NetBSD,$(uname_S))
16+
OS:=netbsd
17+
endif
1518
ifeq (OpenBSD,$(uname_S))
1619
OS:=openbsd
1720
endif

std/conv.d

+15-1
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,21 @@ unittest
28622862

28632863
// min and max
28642864
real r = to!real(to!string(real.min_normal));
2865-
assert(to!string(r) == to!string(real.min_normal));
2865+
version(NetBSD)
2866+
{
2867+
// NetBSD notice
2868+
// to!string returns 3.3621e-4932L. It is less than real.min_normal and it is subnormal value
2869+
// Simple C code
2870+
// long double rd = 3.3621e-4932L;
2871+
// printf("%Le\n", rd);
2872+
// has unexpected result: 1.681050e-4932
2873+
//
2874+
// Bug report: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=50937
2875+
}
2876+
else
2877+
{
2878+
assert(to!string(r) == to!string(real.min_normal));
2879+
}
28662880
r = to!real(to!string(real.max));
28672881
assert(to!string(r) == to!string(real.max));
28682882
}

std/datetime.d

+20
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,20 @@ public:
452452
ts.tv_nsec / 100 +
453453
hnsecsToUnixEpoch;
454454
}
455+
else version(NetBSD)
456+
{
457+
static if(clockType == ClockType.second)
458+
return unixTimeToStdTime(core.stdc.time.time(null));
459+
else
460+
{
461+
timeval tv;
462+
if(gettimeofday(&tv, null) != 0)
463+
throw new TimeException("Call to gettimeofday() failed");
464+
return convert!("seconds", "hnsecs")(tv.tv_sec) +
465+
convert!("usecs", "hnsecs")(tv.tv_usec) +
466+
hnsecsToUnixEpoch;
467+
}
468+
}
455469
else version(Solaris)
456470
{
457471
static if(clockType == ClockType.second)
@@ -27049,6 +27063,7 @@ public:
2704927063
version(Posix)
2705027064
{
2705127065
version(FreeBSD) enum utcZone = "Etc/UTC";
27066+
else version(NetBSD) enum utcZone = "UTC";
2705227067
else version(linux) enum utcZone = "UTC";
2705327068
else version(OSX) enum utcZone = "UTC";
2705427069
else static assert(0, "The location of the UTC timezone file on this Posix platform must be set.");
@@ -27488,6 +27503,10 @@ public:
2748827503
// A bug on FreeBSD 9+ makes it so that this test fails.
2748927504
// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=168862
2749027505
}
27506+
else version(NetBSD)
27507+
{
27508+
// The same bug on NetBSD 7+
27509+
}
2749127510
else
2749227511
{
2749327512
setTZEnvVar("America/Los_Angeles");
@@ -28929,6 +28948,7 @@ public:
2892928948

2893028949
if(!tzName.extension().empty ||
2893128950
!tzName.startsWith(subName) ||
28951+
tzName == "leapseconds" ||
2893228952
tzName == "+VERSION")
2893328953
{
2893428954
continue;

std/file.d

+7
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,9 @@ version (OSX)
23942394
else version (FreeBSD)
23952395
private extern (C) int sysctl (const int* name, uint namelen, void* oldp,
23962396
size_t* oldlenp, const void* newp, size_t newlen);
2397+
else version (NetBSD)
2398+
private extern (C) int sysctl (const int* name, uint namelen, void* oldp,
2399+
size_t* oldlenp, const void* newp, size_t newlen);
23972400

23982401
/**
23992402
* Returns the full path of the current executable.
@@ -2463,6 +2466,10 @@ else version (FreeBSD)
24632466

24642467
return buffer.assumeUnique;
24652468
}
2469+
else version (NetBSD)
2470+
{
2471+
return readLink("/proc/self/exe");
2472+
}
24662473
else version (Solaris)
24672474
{
24682475
import core.sys.posix.unistd : getpid;

std/mmfile.d

+3-1
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,11 @@ unittest // Issue 14994, 14995
683683
import std.file : deleteme;
684684
import std.typecons : scoped;
685685

686-
// Zero-length map may or may not be valid on OSX
686+
// Zero-length map may or may not be valid on OSX and NetBSD
687687
version (OSX)
688688
import std.exception : verifyThrown = collectException;
689+
version (NetBSD)
690+
import std.exception : verifyThrown = collectException;
689691
else
690692
import std.exception : verifyThrown = assertThrown;
691693

std/parallelism.d

+9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ else version(FreeBSD)
9898
{
9999
version = useSysctlbyname;
100100
}
101+
else version(NetBSD)
102+
{
103+
version = useSysctlbyname;
104+
}
105+
101106

102107
version(Windows)
103108
{
@@ -146,6 +151,10 @@ else version(useSysctlbyname)
146151
{
147152
auto nameStr = "hw.ncpu\0".ptr;
148153
}
154+
else version(NetBSD)
155+
{
156+
auto nameStr = "hw.ncpu\0".ptr;
157+
}
149158

150159
uint ans;
151160
size_t len = uint.sizeof;

std/socket.d

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ string formatSocketError(int err) @trusted
179179
else
180180
return "Socket error " ~ to!string(err);
181181
}
182+
else version (NetBSD)
183+
{
184+
auto errs = strerror_r(err, buf.ptr, buf.length);
185+
if (errs == 0)
186+
cs = buf.ptr;
187+
else
188+
return "Socket error " ~ to!string(err);
189+
}
182190
else version (Solaris)
183191
{
184192
auto errs = strerror_r(err, buf.ptr, buf.length);

std/stdio.d

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ version (FreeBSD)
5959
version = HAS_GETDELIM;
6060
}
6161

62+
version (NetBSD)
63+
{
64+
version = GENERIC_IO;
65+
version = HAS_GETDELIM;
66+
}
67+
6268
version (Solaris)
6369
{
6470
version = GENERIC_IO;

std/system.d

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ immutable
3434
linux, /// All Linux Systems
3535
osx, /// Mac OS X
3636
freeBSD, /// FreeBSD
37+
netBSD, /// NetBSD
3738
solaris, /// Solaris
3839
android, /// Android
3940
otherPosix /// Other Posix Systems
@@ -46,6 +47,7 @@ immutable
4647
else version(linux) OS os = OS.linux;
4748
else version(OSX) OS os = OS.osx;
4849
else version(FreeBSD) OS os = OS.freeBSD;
50+
else version(NetBSD) OS os = OS.netBSD;
4951
else version(Posix) OS os = OS.otherPosix;
5052
else static assert(0, "Unknown OS.");
5153

0 commit comments

Comments
 (0)