31#if __has_include(<unistd.h>)
45#if defined(__APPLE__) && defined(__MACH__)
46#include <mach-o/dyld.h>
49#if (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
50#include <sys/sysctl.h>
61 if (
stat(name_c, &buf) == 0) {
79 *ierr =
stat(name_c, &statbuf);
82 mtime = statbuf.st_mtime;
83 timeinfo = localtime(&mtime);
84 mod_time_c = asctime(timeinfo);
87 mod_time_c = malloc(
sizeof(
char));
92 printf(
"ierr = %i\n", *ierr);
102 ierr =
stat(name_c, &statbuf);
105 return S_ISDIR(statbuf.st_mode);
111void oct_rm(
char * name_c) {
121 tmp = realpath(
fn, NULL);
127 strcpy(dn, dirname(
fn));
131 strcpy(bn, basename(
fn));
136 tmp = getenv(name_c);
154 for (
i = 0;
i < 16384;
i++)
159 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
167 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
175 for (
i = i1;
i <= i2;
i++)
176 if (
i >= 0 &&
i < 16384)
206 *sec = (int)tv.tv_sec;
207 *usec = (
int)tv.tv_usec;
222double FC_FUNC_(oct_clock, OCT_CLOCK)() {
225 FC_FUNC_(oct_gettimeofday, OCT_GETTIMEOFDAY)(&sec, &usec);
226 return sec + 1.0e-6 * usec;
228 return (
double)
clock() / CLOCKS_PER_SEC;
237 req.tv_nsec = (long)*nsec;
238 nanosleep(&req, NULL);
255 pf = fopen(name_c,
"r");
259 while ((c = getc(pf)) != EOF) {
274 OCT_BREAK_C_STRING)(
char **str,
char **
s,
281 if (*
s == NULL || **
s ==
'\0') {
286 for (c = line; **
s !=
'\0' && **
s !=
'\n'; (*s)++, c++)
292 strcpy(line_f, line);
320 char *num_start, *num_end;
321 double read_value, min;
322 int found_something, read_tag;
339 num_start = strchr(ent->d_name,
'_');
341 if (num_start != NULL) {
345 read_value = strtod(num_start, &num_end);
347 if (num_end == num_start)
351 if (num_end[0] ==
'_') {
353 num_start = num_end + 1;
354 read_tag = (int)strtol(num_start, &num_end, 10);
355 if (num_end == num_start)
357 if (read_tag != *tag)
364 if (!found_something) {
377 if (found_something) {
385#warning directory search not compiled
386 fprintf(
stderr,
"Warning: Directory search not available since certain C "
387 "functions are not available.\n");
392#if !(defined(__APPLE__) && defined(__MACH__))
396 snprintf(path,
sizeof(path),
"/sys/devices/system/cpu/cpu0/cache/index%d/%s",
index, name);
400 int nread = fscanf(
file,
"%31s", text);
410#if defined(__APPLE__) && defined(__MACH__)
412 size_t length =
sizeof(value);
413 if (sysctlbyname(level == 1 ?
"hw.perflevel0.l1dcachesize" :
"hw.perflevel0.l2cachesize",
414 &value, &
length, NULL, 0) != 0 || value <= 0) {
417 sysctlbyname(level == 1 ?
"hw.l1dcachesize" :
"hw.l2cachesize", &value, &
length, NULL, 0);
422 sysctlbyname(
"hw.cachelinesize", &value, &
length, NULL, 0);
423 *line_size = (int)value;
428 if (atoi(text) != level)
435 if (sscanf(text,
"%d%c", &value, &unit) >= 1)
436 *size = value * (unit ==
'K' ? 1024 : unit ==
'M' ? 1024 * 1024 : 1);
439 *line_size = atoi(text);
445void *
FC_FUNC_(oct_get_memory_usage, OCT_GET_MEMORY_USAGE)() {
447 static size_t pagesize = 0;
457 sprintf(
s,
"%s%d%s",
"/proc/", pid,
"/statm");
458 if ((
f = fopen(
s,
"r")) == (
FILE *)NULL)
460 fscanf(
f,
"%lu", &mem);
463 return (
void *)(mem * pagesize);
473#if defined(__APPLE__) && defined(__MACH__)
477 ret = _NSGetExecutablePath(buf, &bufsize);
479 buf = (
char *)malloc(bufsize);
481 ret = _NSGetExecutablePath(buf, &bufsize);
483 tmp = realpath(buf, NULL);
485#elif defined(linux) || defined(__linux)
486 tmp = realpath(
"/proc/self/exe", NULL);
487#elif defined(__NETBSD__) || defined(__NetBSD__)
488 tmp = realpath(
"/proc/curproc/exe", NULL);
489#elif defined(__DragonFly__)
490 tmp = realpath(
"/proc/curproc/file", NULL);
491#elif defined(__FreeBSD__)
492 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
495 ret = sysctl(mib, 4, NULL, &len, NULL, 0);
499 ret = sysctl(mib, 4, tmp, &len, NULL, 0);
503 tmp = (
char *)malloc(1);
508 fprintf(
stderr,
"%s:%d: in %s: Something went wrong\n", __FILE__, __LINE__, __func__);
509 tmp = (
char *)malloc(1);
char * getcwd(char *__buf, size_t __size) __attribute__((__nothrow__
if write to the Free Software Franklin Fifth USA !The assertions are ignored if the code is compiled in not debug when !prints out the assertion the file
double fabs(double __x) __attribute__((__nothrow__
double fn(const gsl_vector *v, void *params)
integer, parameter, public length
real(real64) function s()
static int read_cache_attribute(int index, const char *name, char *text)
long int sysconf(int __name) __attribute__((__nothrow__
void oct_wfs_list(char *str_c, fint l[16384])
void oct_executable_path(char *path)
void oct_rm(char *name_c)
void oct_getcwd(char *name)
int mkdir(const char *__path, __mode_t __mode) __attribute__((__nothrow__
void oct_basename(char *fn, char *bn)
int gettimeofday(struct timeval *__restrict __tv, void *__restrict __tz) __attribute__((__nothrow__
void oct_sysname(char *name_c)
int oct_number_of_lines(char *name_c)
void oct_cache_info(int level, int *size, int *line_size)
void oct_stat(fint *ierr, char *name_c, char *mod_time_c)
void oct_realpath(char *fn, char *rn)
void oct_dirname(char *fn, char *dn)
void oct_getenv(char *name_c, char *var_c)
DIR DIR struct dirent * readdir(DIR *__dirp) __attribute__((__nonnull__(1)))
DIR * opendir(const char *__name) __attribute__((__nonnull__(1))) __attribute__((__malloc__)) __attribute__((__malloc__(closedir
int closedir(DIR *__dirp) __attribute__((__nonnull__(1)))
int oct_dir_exists(char *name_c)
void FC_FUNC_(oct_progress_bar, OCT_PROGRESS_BAR)
int stat(const char *__restrict __file, struct stat *__restrict __buf) __attribute__((__nothrow__
int fclose(FILE *__stream)
void oct_search_file_lr(double *freq, const fint *tag, fint *ierr, char *name_c)
void progress_bar(int actual, int max)
Progress bar dispatcher.
void oct_mkdir(char *name_c)
const int *restrict index
static double f(double w, void *p)