diff options
author | Mystery Man <unknown@mandriva.org> | 2003-02-25 09:37:46 +0000 |
---|---|---|
committer | Mystery Man <unknown@mandriva.org> | 2003-02-25 09:37:46 +0000 |
commit | 07dc2ddb40089c216ab4ff323de177ecab8f02ef (patch) | |
tree | 0b88fcba964e83b283b89aab8740fc3cdcd0d939 /mdk-stage1/dietlibc/libcruft/sysconf_cpus.c | |
parent | 327bd24f8e4291bd1882de1990dd7339f781a9cb (diff) | |
download | drakx-backup-do-not-use-07dc2ddb40089c216ab4ff323de177ecab8f02ef.tar drakx-backup-do-not-use-07dc2ddb40089c216ab4ff323de177ecab8f02ef.tar.gz drakx-backup-do-not-use-07dc2ddb40089c216ab4ff323de177ecab8f02ef.tar.bz2 drakx-backup-do-not-use-07dc2ddb40089c216ab4ff323de177ecab8f02ef.tar.xz drakx-backup-do-not-use-07dc2ddb40089c216ab4ff323de177ecab8f02ef.zip |
This commit was manufactured by cvs2svn to create branch
'R9_0-64bit-branch'.
Diffstat (limited to 'mdk-stage1/dietlibc/libcruft/sysconf_cpus.c')
-rw-r--r-- | mdk-stage1/dietlibc/libcruft/sysconf_cpus.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c b/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c new file mode 100644 index 000000000..b5361d0a4 --- /dev/null +++ b/mdk-stage1/dietlibc/libcruft/sysconf_cpus.c @@ -0,0 +1,64 @@ +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include "dietfeatures.h" + +/* + * by Olaf Dreesen + * + * arm NO SMP ?!? (return 1) + * + * alpha -> cpus detected\t\t: <nr>\n + * sparc -> ncpus active\t: <nr>\n + * + * default -> processor\t: <cpunr>\n (one per cpu) + */ + +#ifdef SLASH_PROC_OK +int __sc_nr_cpus(void); +int __sc_nr_cpus() { +#if defined(__arm__) + return 1; +#else + int fd; + fd = open("/proc/cpuinfo", O_RDONLY); + if (fd==-1) return 1; /* fallback if no proc-fs mounted */ + else { + int n,nr=0; + char buf[2048]; /* holds ~6 cpuinfos */ + + while((n=read(fd,buf,sizeof(buf)))>0) { + register int i=0; + while (i<n) { +#if defined(__alpha__) + if ((buf[i]=='c')&&(!memcmp(buf+i,"cpus detected",13))) { + i+=17; + nr=atoi(buf+i); + break; + } +#elif defined(__sparc__) + if ((buf[i]=='n')&&(!memcmp(buf+i,"ncpus active",12))) { + i+=15; + nr=atoi(buf+i); + break; + } +#else /* DEFAULT */ + if ((buf[i]=='p')&&(!memcmp(buf+i,"processor",9))) { + ++nr; + i+=9; + } +#endif + while(buf[i++]!='\n'); /* skip rest of line */ + } + } + close(fd); + return nr; + } +#endif +} +#else +int __sc_nr_cpus() { + return 1; /* kludge kludge ;-) */ +} +#endif |