ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Fri Oct 19, 2018 3:56 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Feb 25, 2017 3:37 pm 
Offline
Wayist

Joined: Sat Jan 14, 2012 12:53 am
Posts: 28
Turns out FreeBSD can also use sysconf() :D
Also, don't rely on /proc being mounted: many users don't mount proc.

Code:
diff --git a/src/getself.c b/src/getself.c
index 88e3ab4d5..a6933b7e0 100644
--- a/src/getself.c
+++ b/src/getself.c
@@ -42,24 +42,25 @@ int get_number_cpus()
 #elif defined(SELFEXE_BSD)
 #include <limits.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <sys/sysctl.h>
+
 const char *get_self_executable(int argc, char **argv)
 {
        static char res[PATH_MAX];
-       // Like linux, but /proc is not always mounted
-       //  return 0 if it's not
-       if (realpath("/proc/curproc/file", res)) return NULL;
+       int mib[4];
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_PROC;
+       mib[2] = KERN_PROC_PATHNAME;
+       mib[3] = -1;
+       size_t cb = sizeof(res);
+       sysctl(mib,4,res,&cb,NULL,0);
        return res;
 }
 
-#import <sys/sysctl.h>
-
 int get_number_cpus()
 {
-       int count;
-       size_t size=sizeof(count);
-       
-       if (sysctlbyname("hw.ncpu",&count,&size,NULL,0)) return 1;
-       return count;
+       return sysconf(_SC_NPROCESSORS_ONLN);
 }
 
 #elif defined(SELFEXE_WINDOWS)


Top
 Profile  
 
PostPosted: Fri Mar 03, 2017 7:15 pm 
Offline
Wayist

Joined: Sat Jan 14, 2012 12:53 am
Posts: 28
I release copyright for this change to DarkGod to license as he wishes.


Top
 Profile  
 
PostPosted: Wed Mar 08, 2017 4:52 pm 
Offline
Master of Eyal

Joined: Wed Jul 24, 2002 9:26 pm
Posts: 10230
Location: Angolwen
Thanks :)

_________________
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group