<commit_before>// miscellaneos functions, mostly used during startup in
// a user process; RTAPI not necessarily available

#include "config.h"
#include "rtapi.h"
#include "inifile.h"           /* iniFind() */

#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <limits.h>		/* PATH_MAX */
#include <stdlib.h>		/* exit() */

// really in nucleus/heap.h but we rather get away with minimum include files
#ifndef XNHEAP_DEV_NAME
#define XNHEAP_DEV_NAME  "/dev/rtheap"
#endif

// if this exists, and contents is '1', it's RT_PREEMPT
#define PREEMPT_RT_SYSFS "/sys/kernel/realtime"

// dev/rtai_shm visible only after 'realtime start'
#define DEV_RTAI_SHM "/dev/rtai_shm"

// static storage of kernel module directory
static char kmodule_dir[PATH_MAX];

FILE *rtapi_inifile = NULL;

int kernel_is_xenomai()
{
    struct stat sb;
    return ((stat(XNHEAP_DEV_NAME, &sb) == 0)  &&
	    ((sb.st_mode & S_IFMT) == S_IFCHR));
}

int kernel_is_rtai()
{
    struct stat sb;
    // this works only after 'realtime start'
    return ((stat(DEV_RTAI_SHM, &sb) == 0)  && ((sb.st_mode & S_IFMT) == S_IFCHR));
}

int kernel_is_rtpreempt()
{
    FILE *fd;
    int retval = 0;

    if ((fd = fopen(PREEMPT_RT_SYSFS,"r")) != NULL) {
	int flag;<commit_msg>kernel autodetect: rework RTAI detection<commit_after>// miscellaneos functions, mostly used during startup in
// a user process; RTAPI not necessarily available

#include "config.h"
#include "rtapi.h"
#include "inifile.h"           /* iniFind() */

#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <limits.h>		/* PATH_MAX */
#include <stdlib.h>		/* exit() */

// really in nucleus/heap.h but we rather get away with minimum include files
#ifndef XNHEAP_DEV_NAME
#define XNHEAP_DEV_NAME  "/dev/rtheap"
#endif

// if this exists, and contents is '1', it's RT_PREEMPT
#define PREEMPT_RT_SYSFS "/sys/kernel/realtime"

// Exists on RTAI and Xenomai
#define PROC_IPIPE "/proc/ipipe"

// Exists on Xenomai but not on RTAI
#define PROC_IPIPE_XENOMAI "/proc/ipipe/Xenomai"

// static storage of kernel module directory
static char kmodule_dir[PATH_MAX];

FILE *rtapi_inifile = NULL;

int kernel_is_xenomai()
{
    struct stat sb;

    return ((stat(XNHEAP_DEV_NAME, &sb) == 0) &&
	    (stat(PROC_IPIPE_XENOMAI, &sb) == 0));
}

int kernel_is_rtai()
{
    struct stat sb;

    return ((stat(PROC_IPIPE, &sb) == 0) && 
	    (stat(PROC_IPIPE_XENOMAI, &sb) != 0));
}

int kernel_is_rtpreempt()
{
    FILE *fd;
    int retval = 0;

    if ((fd = fopen(PREEMPT_RT_SYSFS,"r")) != NULL) {
	int flag;
{'fraction_non_alphanumeric': 0.14167294649585532, 'fraction_numerical': 0.0037678975131876413, 'mean_word_length': 3.8360655737704916, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7555518', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1017, 'n_words': 270}