diff options
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/c/smp.c | 136 |
1 files changed, 119 insertions, 17 deletions
diff --git a/perl-install/c/smp.c b/perl-install/c/smp.c index 886321e06..9cc75978d 100644 --- a/perl-install/c/smp.c +++ b/perl-install/c/smp.c @@ -64,30 +64,132 @@ int sparcDetectSMP(void) } #endif /* __sparc__ */ -/* just a placeholder for now - don't have an SMP machine - need something in place to build - s.benedict */ - #ifdef __powerpc__ +/* minifind.c -- simple find library + * + * Copyright (c) 2002 Terra Soft Solutions, Inc. + * Written by Dan Burcaw <dburcaw@terrasoftsolutions.com> + * + * This software may be freely redistributed under the terms of the GNU + * library public license. + * + * You should have received a copy of the GNU Library Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdio.h> +#include <string.h> +#include <dirent.h> +#include <malloc.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> + +struct pathNode +{ + char *path; + struct pathNode *next; +}; + +struct findNode +{ + struct pathNode *result; + struct pathNode *exclude; +}; + +// insert a node at head of linked-list +static void insert_node(struct pathNode *n, char *path) +{ + struct pathNode *new = (struct pathNode *) malloc(sizeof(struct pathNode)); + new->path = path; + new->next = n->next; + n->next = new; +} + +// return input strip less last character +static char *stripLastChar(char *in) +{ + char *out = malloc(sizeof(char)*strlen(in)); + snprintf(out, strlen(in) - 1, "%s", in); + return out; +} + +// do the work +static char *minifind(char *dir, char *search, struct findNode *list) +{ + char *d = NULL; + int n; + struct dirent **namelist; + struct stat buf; + + if (dir[strlen(dir)-1] == '/') + dir = stripLastChar(dir); + + // check is there is an exact filematch to dir + // when search is not specified + if (search == NULL) + { + if (lstat(dir, &buf) == 0) + insert_node(list->result, dir); + return 0; + } + + n = scandir(dir, &namelist, 0, alphasort); + if (n >= 0) + { + while (n--) + { + d = malloc(sizeof(char) * (strlen(dir) \ + + strlen(namelist[n]->d_name)+1)); + sprintf(d, "%s/%s", dir, namelist[n]->d_name); + if (strstr(namelist[n]->d_name, search)) + insert_node(list->result, d); + + if ((lstat(d, &buf) == 0) && S_ISDIR(buf.st_mode)) + { + if (strcmp(namelist[n]->d_name, ".") && + strcmp(namelist[n]->d_name, "..")) + d = minifind(d, search, list); + } + free(namelist[n]); + } + free(namelist); + return d; + } + return 0; +} + int ppcDetectSMP(void) { - int issmp = 0; + int issmp = -1; FILE *f; - - f = fopen("/proc/cpuinfo", "r"); - if (f) { - char buff[1024]; + struct findNode *list = (struct findNode *) malloc(sizeof(struct findNode)); + struct pathNode *n; - while (fgets (buff, 1024, f) != NULL) { - if (!strncmp (buff, "ncpus active\t: ", 15)) { - if (strtoul (buff + 15, NULL, 0) > 1) - issmp = 1; - break; + list->result = (struct pathNode *) malloc(sizeof(struct pathNode)); + list->result->path = NULL; + list->result->next = list->result; + + minifind("/proc/device-tree/cpus", "device_type", list); + + for (n = list->result->next; n != list->result; n = n->next) + { + f = fopen(n->path, "r"); + if (f) { + char buff[1024]; + while (fgets (buff, 1024, f) != NULL) { + if (!strncmp (buff, "cpu", 3)) + { + issmp++; + break; + } + } + fclose(f); } } - fclose(f); - } else - return -1; - + return issmp; } #endif /* __powerpc__ */ |