MAOS
Multithreaded Adaptive Optics Simulator
misc.h File Reference

Data Structures

struct  argopt_t
 

Macros

#define strdup   mystrdup /*our strdup handles NULL correctly, and talk to mem.c */
 
#define strndup   mystrndup
 

Functions

char * mydirname (const char *fn)
 
int check_suffix (const char *fn, const char *suffix)
 
int copyfile (const char *src, const char *dest)
 
char * argv2str (int argc, const char *argv[], const char *delim)
 
void print_file (const char *fnin)
 
time_t myclocki (void)
 
double myclockd (void)
 
const char * myasctime (time_t at)
 
char * strtime_pid (void)
 
const char * myhostname (void)
 
char * mygetcwd (void)
 
char * myabspath (const char *path)
 
int mysymlink (const char *source, const char *dest)
 
int mylink (const char *source, const char *dest)
 
int exist (const char *fn)
 
int isdir (const char *fn)
 
int isfile (const char *fn)
 
int islink (const char *fn)
 
int issock (int fd)
 
size_t flen (const char *fn)
 
time_t fmtime (const char *fn)
 
char * stradd (const char *a,...)
 
char * strnadd (int argc, const char *argv[], const char *delim)
 
char * expand_filename (const char *fn)
 
void remove_file_older (const char *fndir, int level, long sec)
 
void mymkdir (const char *format,...)
 
int mystrcmp (const char *a, const char *b)
 
char * mystrndup (const char *A, size_t len)
 
void cloexec (int fd)
 
void mysleep (double sec)
 
int mypause (int fd1, int fd2)
 
long available_space (const char *path)
 
char * mystrdup (const char *A)
 
void parse_argopt (char *cmds, argopt_t *options)
 
void set_realtime (int icpu, int niceness)
 
void free_strarr (char **str, int n)
 

Detailed Description

misc routines.


Data Structure Documentation

◆ argopt_t

struct argopt_t
+ Collaboration diagram for argopt_t:
Data Fields
const char * name

The long name

char key

The short name

int type

The type of result expected

int valtype

The type of input expected: 0: The key does not need value; 1: The key needs value; 2: The key accepts an array of values.

int isfun

Whether val indicate a function pointer 0: The address to put the return results. 1: A function pointer to call.

void * val

The address to put the return result.

int * nval

If val is array, this is the counter.

Function Documentation

◆ mydirname()

char* mydirname ( const char *  fn)

Obtain the dirname of a path. See mybasename().

◆ check_suffix()

int check_suffix ( const char *  fn,
const char *  suffix 
)

Check the suffix of a file.

◆ copyfile()

int copyfile ( const char *  src,
const char *  dest 
)

Copy a file from src to dest

◆ argv2str()

char* argv2str ( int  argc,
const char *  argv[],
const char *  delim 
)

Convert argc, argv to a single string, prefixed by the current directory.

◆ print_file()

void print_file ( const char *  fnin)

Print the content of a file.

◆ myclocki()

time_t myclocki ( void  )

Get current time in seconds as an integer.

◆ myclockd()

double myclockd ( void  )

Get current time in nano-second resolution.

◆ myasctime()

const char* myasctime ( time_t  at)

Get current time in ascii string for easy print. The string contains spaces and is not suitable to use in filename. The returned string should not be modified.

◆ strtime_pid()

char* strtime_pid ( void  )

Get furrent time in ascii string that doesn't contain spaces. Suitable for use in filenames. The returnned string must be freed.

◆ mygetcwd()

char* mygetcwd ( void  )

Get current directory. The returnned string must be freed.

◆ myabspath()

char* myabspath ( const char *  path)

Translate a path into absolute path. The caller shall free the returned string.

◆ mysymlink()

int mysymlink ( const char *  source,
const char *  dest 
)

Create symbolic link

◆ mylink()

int mylink ( const char *  source,
const char *  dest 
)

Create hard link

◆ exist()

int exist ( const char *  fn)

Test whether a file exists.

◆ isdir()

int isdir ( const char *  fn)

Test whether fn is directory

◆ isfile()

int isfile ( const char *  fn)

Test whether fn is ordinary file

◆ islink()

int islink ( const char *  fn)

Test whether fn is a symbolic link

◆ issock()

int issock ( int  fd)

Test whether fd is a socket

◆ flen()

size_t flen ( const char *  fn)

Compute length of file in Bytes

◆ fmtime()

time_t fmtime ( const char *  fn)

Return the modification time of the file

◆ stradd()

char* stradd ( const char *  a,
  ... 
)

Concatenate many strings. Argument list must end with NULL.

◆ strnadd()

char* strnadd ( int  argc,
const char *  argv[],
const char *  delim 
)

Concatenate many strings, like stradd, but arguments are an array of char*

◆ expand_filename()

char* expand_filename ( const char *  fn)

translate a filename into absolute file name that starts with /

◆ remove_file_older()

void remove_file_older ( const char *  fndir,
int  level,
long  sec 
)

Remove files that are older than sec seconds in folder fndir. If sec==0, remove everything.

◆ mymkdir()

void mymkdir ( const char *  format,
  ... 
)

Make dirs recursively. like mkdir -p in bash

◆ mystrcmp()

int mystrcmp ( const char *  a,
const char *  b 
)

Compare two strings upto the length of b. if length of a is less than b, return false. 1 means not equal.

◆ mystrndup()

char* mystrndup ( const char *  A,
size_t  len 
)

Duplicate a string. Check for NULL. Do not call strndup to avoid recursive deadlock.

◆ cloexec()

void cloexec ( int  fd)

Make the fd close on exec.

◆ mysleep()

void mysleep ( double  sec)

wrap of nanosleep

◆ mypause()

int mypause ( int  fd1,
int  fd2 
)

Pause execution and listen input from fd1 and/or fd2 for continuation. Returns new pause flag.

Parameters
fd1first file no, usually 0 for stdin
fd2second file no, usually created from a pipe t

◆ available_space()

long available_space ( const char *  path)

Return available space of mounted file system in bytes.

◆ mystrdup()

char* mystrdup ( const char *  A)

declare strdup so my memory mangement mem.c is happy when DEBUG=1. Handles NULL pointer correctly. Do not call strdup to avoid recursive deadlock.

◆ parse_argopt()

void parse_argopt ( char *  cmds,
argopt_t options 
)

Parse command line arguments. The remaining string contains whatever is not yet parsed. This is more relaxed than the built in getopd

◆ set_realtime()

void set_realtime ( int  icpu,
int  niceness 
)

Set scheduling priorities for the process to enable real time behavior.