X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Futils%2Fos.h;h=42fdea3dad5e99872dc0eac03bc68cf3caa8a4e4;hp=07328dd11a2b0d9aaf96c82c0f920e1d88082070;hb=92b88ad62cefc6aa9029906eccdbdf8643ec8914;hpb=13fe0f9ec3d161fab7a015054649910541d75f5e diff --git a/src/include/utils/os.h b/src/include/utils/os.h index 07328dd..42fdea3 100644 --- a/src/include/utils/os.h +++ b/src/include/utils/os.h @@ -29,11 +29,40 @@ #define SDB_UTILS_OS_H 1 #include +#include #ifdef __cplusplus extern "C" { #endif +/* + * sdb_get_homedir: + * Returns the home directory of the current user. The buffer to hold the + * return value is allocated dynamically and has to be freed by the caller. + * + * Returns: + * - the current user's home directory on success + * - NULL else + */ +char * +sdb_get_homedir(void); + +/* + * sdb_realpath: + * Returns the canonicalized absolute pathname for the specified path. The + * function expands all symbolic links and resolves references to '.', '..', + * and extra slash characters (/). + * + * '~/' at the start of the string will be replaced by the current user's home + * directory. + * + * Returns: + * - the canonicalized absolute pathname on success + * - NULL else + */ +char * +sdb_realpath(const char *path); + /* * sysdb_mkdir_all: * Recursively create the directory 'pathname' (similar to 'mkdir -p' on the @@ -69,6 +98,61 @@ sdb_remove_all(const char *pathname); char * sdb_get_current_user(void); +enum { + SDB_SELECTIN = 0, + SDB_SELECTOUT, + SDB_SELECTERR, +}; + +/* + * sdb_select: + * Wait for a file-descriptor to become ready for I/O operations of the + * specified type. This is a simple wrapper around the select() system call. + * The type argument may be any of the SDB_SELECT* constants. + * + * Returns: + * - the number of file descriptors ready for I/O + * - a negative value on error + */ +int +sdb_select(int fd, int type); + +/* + * sdb_write: + * Write a message to a file-descriptor. This is a simple wrapper around the + * write() system call ensuring that all data is written on success. + * + * Returns: + * - the number of bytes written + * - a negative value on error + */ +ssize_t +sdb_write(int fd, size_t msg_len, const void *msg); + +enum { + SDB_NET_TCP = 1 << 0, + SDB_NET_UDP = 1 << 1, + SDB_NET_IP = SDB_NET_TCP | SDB_NET_UDP, + + SDB_NET_V4 = 1 << 2, + SDB_NET_V6 = 1 << 3, +}; + +/* + * sdb_resolve: + * Resolve the specified address on the specified network which may be a + * bitwise OR of the SDB_NET constants. The network addresses are returned in + * the list pointed to by 'res'. The list is allocated dynamically and has to + * be freed using freeaddrinfo(). + * + * Returns: + * - zero on success + * - an error code else; use gai_strerror() to translate the error into a + * human readable string + */ +int +sdb_resolve(int network, const char *address, struct addrinfo **res); + #ifdef __cplusplus } /* extern "C" */ #endif