utils: add the source files

This commit is contained in:
Boris Faure 2020-06-23 13:27:07 +02:00
parent 3cbcbcd717
commit dd7d88815c
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
2 changed files with 30 additions and 0 deletions

23
src/bin/utils.c Normal file
View File

@ -0,0 +1,23 @@
#include "private.h"
#include "utils.h"
#include <unistd.h>
#include <pwd.h>
Eina_Bool
homedir_get(char *buf, size_t size)
{
const char *home = getenv("HOME");
if (!home)
{
uid_t uid = getuid();
struct passwd *pw = getpwuid(uid);
if (pw) home = pw->pw_dir;
}
if (!home)
{
ERR("Could not get $HOME");
return EINA_FALSE;
}
return eina_strlcpy(buf, home, size) < size;
}

7
src/bin/utils.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _UTILS_H__
#define _UTILS_H__
#include <Eina.h>
Eina_Bool homedir_get(char *buf, size_t size);
#endif