ui-utilcpp 1.10.3
Data Structures | Functions
UI::Util::Sys Namespace Reference

Namespace for system/library calls. More...

Data Structures

class  Exception
 Use this exception class if you want to catch failures on system/library calls. More...
 

Functions

uid_t fsidFromProcfs (pid_t const pid, std::string const &lineId)
 
Drop-in replacements for system(2) and library(3) calls w/ exception handling on errors.
voidcalloc (size_t nmemb, size_t size)
 
voidmalloc (size_t size)
 
void free (void *ptr)
 
int system (char const *s)
 
chargetenv (char const *name)
 
void realpath (char const *path, char *resolved_path)
 
FILEfopen (char const *path, char const *mode)
 
FILEfreopen (char const *path, char const *mode, FILE *stream)
 
void fclose (FILE *fp)
 
mode_t umask (mode_t mask)
 
void chdir (char const *path)
 
void chown (char const *path, uid_t owner, gid_t group)
 
void chmod (char const *path, mode_t mode)
 
void stat (char const *file_name, struct stat *buf)
 
void fstat (int filedes, struct stat *buf)
 
void lstat (char const *file_name, struct stat *buf)
 
void statvfs (char const *path, struct statvfs *buf)
 
void unlink (char const *pathname)
 
void remove (char const *pathname)
 
void rename (char const *oldpath, char const *newpath)
 
int open (char const *pathname, int flags)
 
int open (char const *pathname, int flags, mode_t mode)
 
void close (int fd)
 
void mkdir (char const *pathname, mode_t mode)
 
void rmdir (char const *pathname)
 
int dup (int oldfd)
 
int dup2 (int oldfd, int newfd)
 
int fcntl (int fd, int cmd, long arg)
 
int fcntl (int fd, int cmd, struct flock *lock)
 
int flock (int fd, int operation)
 
struct passwdgetpwnam (char const *name)
 
struct groupgetgrnam (char const *name)
 
ssize_t write (int fd, void const *buf, size_t count)
 
ssize_t read (int fd, void *buf, size_t count)
 
pid_t fork (void)
 
pid_t getpid ()
 
pid_t gettid ()
 
pid_t getppid ()
 
pid_t getpgid (pid_t pid)
 
pid_t waitpid (pid_t pid, int *status, int options)
 
pid_t setsid ()
 
uid_t getuid ()
 
gid_t getgid ()
 
uid_t geteuid ()
 
gid_t getegid ()
 
void seteuid (uid_t euid)
 
void setegid (gid_t egid)
 
void setuid (uid_t uid)
 
void setgid (gid_t gid)
 
uid_t getfsuid (pid_t const pid)
 
gid_t getfsgid (pid_t const pid)
 
void setfsuid (uid_t fsuid)
 
void setfsgid (gid_t fsgid)
 
void getrlimit (int resource, struct rlimit *rlim)
 
void getrusage (int who, struct rusage *usage)
 
void setrlimit (int resource, struct rlimit const *rlim)
 
unsigned int sleep (unsigned int seconds)
 
int socket (int domain, int type, int protocol)
 
void getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
 
void getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
 
std::string getnameinfo (const struct sockaddr *sa, socklen_t salen)
 
void getpeername (int s, struct sockaddr *name, socklen_t *namelen)
 
void getsockname (int s, struct sockaddr *name, socklen_t *namelen)
 
void setsockopt (int s, int level, int optname, void const *optval, socklen_t optlen)
 
void setsockopt_to (int s, int level, int optname, struct timeval const &tv)
 
ssize_t recv (int s, void *buf, size_t len, int flags)
 
ssize_t send (int s, void const *buf, size_t len, int flags)
 
void listen (int s, int backlog)
 
void bind (int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
 
void connect (int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
 
int select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
 
void socketpair (int d, int type, int protocol, int sv[2])
 
void gettimeofday (struct timeval *tv, struct timezone *tz)
 
void settimeofday (struct timeval const *tv, struct timezone const *tz)
 
iconv_t iconv_open (char const *tocode, char const *fromcode)
 
void iconv_close (iconv_t cd)
 
void quotactl (int cmd, char const *special, int id, caddr_t addr)
 
size_t confstr (int name, char *buf, size_t len)
 
std::string getconf (int id)
 Loosely like the shell utility "getconf".
 
FILEfdopen (int fildes, char const *mode)
 

Detailed Description

Namespace for system/library calls.

Purpose

If you use a call that matches any of the points above, please include a wrapper here.

Example usage

Call any of the wrapper somewhere in your code:

...
myStr = getPath();
UI::Util::Sys::remove(myStr);
// as usual, assume success
...

Somewhere in your context-specific exception handler:

...
catch (UI::Util::Sys::Exception const & e)
{
  std::cerr << "System error        : " << e.what() << std::endl;
  std::cerr << "Errno error code was: " << e.getCode() << std::endl;
  std::cerr << "Exception debug     : " << e.getDebug() << std::endl;
}
...

How to add wrappers