/*  This file is part of lsnet.

    Lsnet is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Lsnet is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with lsnet.  If not, see <http://www.gnu.org/licenses/>.
*/
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#define SIZE 1000
//int maxtextbuffer = sizeof(char)*250;
//#define SIZE sizeof(char)*250
#define SIZE 255

int coresdetected() {
	FILE* fp;
	int count = 0; 
	int coresdetected = 0;
	char buf[SIZE];
	if( ( fp = fopen( "/proc/stat", "r" ) ) == NULL ) {
		fprintf( stderr, "Error opening file.\n" );
		exit( 1 );
	}

        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
		if (buf[count] == 'c'){
			if (buf[count+1] == 'p'){
				if (buf[count+2] == 'u'){
					if (buf[count+3] == '0' || buf[count+3] == '1' || buf[count+3] == '2' || buf[count+3] == '3' || buf[count+3] == '4' || buf[count+3] == '5' || buf[count+3] == '6' || buf[count+3] == '7' || buf[count+3] == '8' || buf[count+3] == '9'){
						coresdetected++;
		}
			}
				}
					}
	}
	//printf( "NUMBER OF CORES: %d\n", coresdetected );

	fclose( fp );
	return (coresdetected);
}

