diff options
author | Simon Rettberg | 2015-10-09 16:41:40 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-09 16:41:40 +0200 |
commit | 5c89ced85217787dc0530d6cb4c3b0a74c6fbf87 (patch) | |
tree | cbe4fe3ce57c8e4544c0bae58999a3922812cb7c /src/util.c | |
parent | Merge branch 'master' of dnbd3:openslx-ng/printergui (diff) | |
download | printergui-5c89ced85217787dc0530d6cb4c3b0a74c6fbf87.tar.gz printergui-5c89ced85217787dc0530d6cb4c3b0a74c6fbf87.tar.xz printergui-5c89ced85217787dc0530d6cb4c3b0a74c6fbf87.zip |
WIP: Try move all GUI interaction to the first binaryonegui
This is broken, incomplete code
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..9e7c892 --- /dev/null +++ b/src/util.c @@ -0,0 +1,38 @@ +#include "util.h" +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <pwd.h> +#include <stdio.h> + +char *util_userHome(int uid, char *buffer, size_t len) +{ + struct passwd pwd; + struct passwd *res; + char b[1000]; + getpwuid_r(uid, &pwd, b, sizeof b, &res); + if (res == NULL || res->pw_dir == NULL) + return NULL; + int printret = snprintf(buffer, len, "%s", res->pw_dir); + if (printret < 0 || printret >= (int)len) + return NULL; + buffer[len-1] = '\0'; + return buffer; +} + +char *util_sockPath(int uid, int pid, char *buffer, size_t len) +{ + char home[120]; + if (uid == -1) { + uid = (int)getuid(); + } + if (pid == -1) { + pid = (int)getpid(); + } + if (util_userHome(uid, home, sizeof home) == NULL) + return NULL; + int printret = snprintf(buffer, len, "%s/.printergui.%d", pid); + if (printret < 0 || printret >= (int)len) + return NULL; + return buffer; +} |