30#if __has_include(<unistd.h>)
47void FC_FUNC_(oct_mkdir, OCT_MKDIR)(STR_F_TYPE name STR_ARG1) {
51 TO_C_STR1(name, name_c);
55 if (
stat(name_c, &buf) == 0) {
69void FC_FUNC_(oct_stat, OCT_STAT)(
fint *ierr, STR_F_TYPE name,
70 STR_F_TYPE mod_time STR_ARG2) {
71 char *name_c, *mod_time_c;
76 TO_C_STR1(name, name_c);
77 *ierr =
stat(name_c, &statbuf);
80 mtime = statbuf.st_mtime;
81 timeinfo = localtime(&mtime);
82 mod_time_c = asctime(timeinfo);
85 mod_time_c = malloc(
sizeof(
char));
90 TO_F_STR2(mod_time_c, mod_time);
92 printf(
"ierr = %i\n", *ierr);
99int FC_FUNC_(oct_dir_exists, OCT_DIR_EXISTS)(STR_F_TYPE name STR_ARG1) {
104 TO_C_STR1(name, name_c);
115void FC_FUNC_(oct_rm, OCT_RM)(STR_F_TYPE name STR_ARG1) {
118 TO_C_STR1(name, name_c);
123void FC_FUNC_(oct_getcwd, OCT_GETCWD)(STR_F_TYPE name STR_ARG1) {
129void FC_FUNC_(oct_realpath, OCT_REALPATH)(STR_F_TYPE fnam,
130 STR_F_TYPE rnam STR_ARG2) {
131 char *fn = NULL, *rn = NULL;
133 rn = realpath(fn, NULL);
144void FC_FUNC_(oct_dirname, OCT_DIRNAME)(STR_F_TYPE fnam,
145 STR_F_TYPE dnam STR_ARG2) {
146 char *fn = NULL, *dn = NULL;
158void FC_FUNC_(oct_basename, OCT_BASENAME)(STR_F_TYPE fnam,
159 STR_F_TYPE bnam STR_ARG2) {
160 char *fn = NULL, *bn = NULL;
172void FC_FUNC_(oct_getenv, OCT_GETENV)(STR_F_TYPE var,
173 STR_F_TYPE value STR_ARG2) {
174 char *name_c, *var_c;
176 TO_C_STR1(var, name_c);
177 var_c = getenv(name_c);
181 TO_F_STR2(var_c, value);
183 TO_F_STR2(
"", value);
189void FC_FUNC_(oct_wfs_list, OCT_WFS_LIST)(STR_F_TYPE str,
190 fint l[16384] STR_ARG1) {
192 char c[20], *c1, *str_c, *
s;
194 TO_C_STR1(str, str_c);
198 for (
i = 0;
i < 16384;
i++)
203 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
211 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
219 for (
i = i1;
i <= i2;
i++)
220 if (
i >= 0 &&
i < 16384)
234void FC_FUNC_(oct_progress_bar, OCT_PROGRESS_BAR)(
fint *a,
fint *max) {
242void FC_FUNC_(oct_gettimeofday, OCT_GETTIMEOFDAY)(
fint *sec,
fint *usec) {
252 *sec = (int)tv.tv_sec;
253 *usec = (
int)tv.tv_usec;
268double FC_FUNC_(oct_clock, OCT_CLOCK)() {
271 FC_FUNC_(oct_gettimeofday, OCT_GETTIMEOFDAY)(&sec, &usec);
272 return sec + 1.0e-6 * usec;
274 return (
double)
clock() / CLOCKS_PER_SEC;
278void FC_FUNC_(oct_nanosleep, OCT_NANOSLEEP)(
fint *sec,
fint *nsec) {
284 nanosleep(&req, NULL);
288void FC_FUNC_(oct_sysname, OCT_SYSNAME)(STR_F_TYPE name STR_ARG1) {
292 TO_F_STR1(name_c, name);
296int FC_FUNC_(oct_number_of_lines,
297 OCT_NUMBER_OF_LINES)(STR_F_TYPE name STR_ARG1) {
303 TO_C_STR1(name, name_c);
304 pf = fopen(name_c,
"r");
309 while ((c = getc(pf)) != EOF) {
323void FC_FUNC_(oct_break_c_string,
324 OCT_BREAK_C_STRING)(
char **str,
char **
s,
325 STR_F_TYPE line_f STR_ARG1) {
331 if (*
s == NULL || **
s ==
'\0') {
336 for (c = line; **
s !=
'\0' && **
s !=
'\n'; (*s)++, c++)
342 TO_F_STR1(line, line_f);
364void FC_FUNC_(oct_search_file_lr,
365 OCT_SEARCH_FILE_LR)(
double *freq,
const fint *tag,
fint *ierr,
366 STR_F_TYPE dirname STR_ARG1) {
372 char *num_start, *num_end;
373 double read_value, min;
374 int found_something, read_tag;
376 TO_C_STR1(dirname, name_c);
393 num_start = strchr(ent->d_name,
'_');
395 if (num_start != NULL) {
399 read_value = strtod(num_start, &num_end);
401 if (num_end == num_start)
405 if (num_end[0] ==
'_') {
407 num_start = num_end + 1;
408 read_tag = (int)strtol(num_start, &num_end, 10);
409 if (num_end == num_start)
411 if (read_tag != *tag)
418 if (!found_something) {
431 if (found_something) {
439#warning directory search not compiled
440 fprintf(
stderr,
"Warning: Directory search not available since certain C "
441 "functions are not available.\n");
446void *FC_FUNC_(oct_get_memory_usage, OCT_GET_MEMORY_USAGE)() {
448 static size_t pagesize = 0;
458 sprintf(
s,
"%s%d%s",
"/proc/", pid,
"/statm");
459 if ((f = fopen(
s,
"r")) == (
FILE *)NULL)
461 fscanf(f,
"%lu", &mem);
464 return (
void *)(mem * pagesize);
470void FC_FUNC_(oct_exit_failure, OCT_EXIT_FAILURE)() { exit(EXIT_FAILURE); }
double fabs(double __x) __attribute__((__nothrow__
real(real64) function s()
long int sysconf(int __name) __attribute__((__nothrow__
int mkdir(const char *__path, __mode_t __mode) __attribute__((__nothrow__
int gettimeofday(struct timeval *__restrict __tv, void *__restrict __tz) __attribute__((__nothrow__
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 stat(const char *__restrict __file, struct stat *__restrict __buf) __attribute__((__nothrow__
int fclose(FILE *__stream)
void progress_bar(int actual, int max)
__syscall_slong_t tv_nsec