2016-03-12 01:29:14 +05:30
|
|
|
/* Unix */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
2019-02-11 23:16:14 +05:30
|
|
|
#include <signal.h>
|
2020-07-25 13:29:22 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2020-09-06 21:19:00 +05:30
|
|
|
#include "zlib.h"
|
2016-03-12 01:29:14 +05:30
|
|
|
|
|
|
|
/* http://stackoverflow.com/questions/30279228/is-there-an-alternative-to-getcwd-in-fortran-2003-2008 */
|
|
|
|
|
2019-02-11 23:16:14 +05:30
|
|
|
|
2016-09-20 10:38:31 +05:30
|
|
|
int isdirectory_c(const char *dir){
|
|
|
|
struct stat statbuf;
|
2018-05-26 02:52:32 +05:30
|
|
|
if(stat(dir, &statbuf) != 0) /* error */
|
|
|
|
return 0; /* return "NO, this is not a directory" */
|
|
|
|
return S_ISDIR(statbuf.st_mode); /* 1 => is directory, 0 => this is NOT a directory */
|
2016-09-20 10:38:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-12 01:29:14 +05:30
|
|
|
void getcurrentworkdir_c(char cwd[], int *stat ){
|
2020-01-26 16:49:36 +05:30
|
|
|
char cwd_tmp[4096];
|
2016-03-12 01:29:14 +05:30
|
|
|
if(getcwd(cwd_tmp, sizeof(cwd_tmp)) == cwd_tmp){
|
2016-05-05 19:46:21 +05:30
|
|
|
strcpy(cwd,cwd_tmp);
|
2016-03-12 01:29:14 +05:30
|
|
|
*stat = 0;
|
2016-05-05 18:41:28 +05:30
|
|
|
}
|
2016-03-12 01:29:14 +05:30
|
|
|
else{
|
|
|
|
*stat = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:38:31 +05:30
|
|
|
|
2018-05-26 02:52:32 +05:30
|
|
|
void gethostname_c(char hostname[], int *stat){
|
2020-01-26 16:49:36 +05:30
|
|
|
char hostname_tmp[4096];
|
2016-09-20 10:38:31 +05:30
|
|
|
if(gethostname(hostname_tmp, sizeof(hostname_tmp)) == 0){
|
|
|
|
strcpy(hostname,hostname_tmp);
|
|
|
|
*stat = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*stat = 1;
|
|
|
|
}
|
2016-03-12 01:29:14 +05:30
|
|
|
}
|
2018-05-26 02:52:32 +05:30
|
|
|
|
|
|
|
|
|
|
|
int chdir_c(const char *dir){
|
|
|
|
return chdir(dir);
|
|
|
|
}
|
2019-02-11 23:16:14 +05:30
|
|
|
|
2019-03-24 16:29:00 +05:30
|
|
|
void signalterm_c(void (*handler)(int)){
|
|
|
|
signal(SIGTERM, handler);
|
|
|
|
}
|
|
|
|
|
2019-02-11 23:16:14 +05:30
|
|
|
void signalusr1_c(void (*handler)(int)){
|
|
|
|
signal(SIGUSR1, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void signalusr2_c(void (*handler)(int)){
|
|
|
|
signal(SIGUSR2, handler);
|
2019-03-24 16:29:00 +05:30
|
|
|
}
|
2020-09-06 21:19:00 +05:30
|
|
|
|
|
|
|
void inflate_c(const uLong *s_deflated, const uLong *s_inflated, const Byte deflated[], Byte inflated[]){
|
|
|
|
/* make writable copy, uncompress will write to it */
|
|
|
|
uLong s_inflated_;
|
|
|
|
s_inflated_ = *s_inflated;
|
|
|
|
|
|
|
|
if(uncompress((Bytef *)inflated, &s_inflated_, (Bytef *)deflated, *s_deflated) == Z_OK)
|
|
|
|
return;
|
|
|
|
else{
|
|
|
|
for(uLong i=0;i<*s_inflated;i++){
|
|
|
|
inflated[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|