sys functions working
This commit is contained in:
@@ -38,7 +38,7 @@ bool Buffer::resize(size_t new_size)
|
||||
return true;
|
||||
}
|
||||
|
||||
int Buffer::add_end(uint8_t *data, size_t data_size)
|
||||
uint32_t Buffer::add_end(uint8_t *data, size_t data_size)
|
||||
{
|
||||
if (taken + data_size > size)
|
||||
if (!resize(size + data_size))
|
||||
|
@@ -45,9 +45,9 @@ void delete_logininfo_from_buffer(Buffer &buffer, int index_of_pass)
|
||||
|
||||
void add_logininfo_to_buffer(Buffer &buffer, const char *label, const char *username, const char *password)
|
||||
{
|
||||
int label_start = buffer.add_end((uint8_t *)label, strlen(label) + 1);
|
||||
int username_start = buffer.add_end((uint8_t *)username, strlen(username) + 1);
|
||||
int password_start = buffer.add_end((uint8_t *)password, strlen(password) + 1);
|
||||
uint32_t label_start = buffer.add_end((uint8_t *)label, strlen(label) + 1);
|
||||
uint32_t username_start = buffer.add_end((uint8_t *)username, strlen(username) + 1);
|
||||
uint32_t password_start = buffer.add_end((uint8_t *)password, strlen(password) + 1);
|
||||
|
||||
Index *index = (Index *)buffer.buffer;
|
||||
|
||||
|
@@ -119,22 +119,101 @@ std::optional<std::string> get_save_path()
|
||||
|
||||
#else
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
bool put_data_on_clipboard(const char *text)
|
||||
{
|
||||
// TODO
|
||||
size_t len = strlen(text);
|
||||
if (len == 0)
|
||||
{
|
||||
printf("Text is empty\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open a pipe to xclip command
|
||||
FILE *pipe = popen("xclip -selection clipboard", "w");
|
||||
if (!pipe)
|
||||
{
|
||||
printf("Failed to open pipe to xclip\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write text to xclip
|
||||
if (fwrite(text, 1, len, pipe) != len)
|
||||
{
|
||||
printf("Failed to write text to xclip\n");
|
||||
pclose(pipe);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Close the pipe
|
||||
pclose(pipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string get_user_password()
|
||||
{
|
||||
// TODO
|
||||
return "123";
|
||||
struct termios oldt, newt;
|
||||
|
||||
// Save the current terminal attributes
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
|
||||
// Copy the old settings to the new settings
|
||||
newt = oldt;
|
||||
|
||||
// Disable echo input
|
||||
newt.c_lflag &= ~ECHO;
|
||||
|
||||
// Apply the new settings
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
|
||||
// Take input
|
||||
std::string ipt;
|
||||
std::getline(std::cin, ipt);
|
||||
|
||||
// Otherwise next cout will print into the same line
|
||||
std::cout << std::endl;
|
||||
|
||||
// Restore the terminal attributes
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
|
||||
return ipt;
|
||||
}
|
||||
|
||||
std::optional<std::string> get_save_path()
|
||||
{
|
||||
// TODO
|
||||
return "save.bin";
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
const char *homeDir = getenv("HOME");
|
||||
if (homeDir == nullptr)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
fs::path userDirectory(homeDir);
|
||||
userDirectory /= ".password_manager";
|
||||
|
||||
if (!fs::exists(userDirectory))
|
||||
{
|
||||
// Directory doesn't exist, create it
|
||||
if (!fs::create_directory(userDirectory))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
else if (!fs::is_directory(userDirectory))
|
||||
{
|
||||
// Path exists but is not a directory
|
||||
return {};
|
||||
}
|
||||
|
||||
userDirectory /= "save.txt";
|
||||
|
||||
return userDirectory.string();
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user