#include <iostream>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
using namespace std;
class my_Path
{
private:
char *symbolic_ln;
char my_buffer[PATH_MAX];
char *last_symbol;
char symbol;
size_t size;
public:
my_Path();
size_t size_Path();
void write_Path();
};
my_Path::my_Path()
{
symbolic_ln="/proc/self/exe";
size=sizeof(my_buffer);
symbol='\0';
}
size_t my_Path::size_Path()
{
if(readlink(symbolic_ln,my_buffer,size)<=0)
return -1;
last_symbol=strrchr(my_buffer,'/');
if(last_symbol==NULL)
return -1;
last_symbol++;
*last_symbol=symbol;
return (size_t) (last_symbol-my_buffer);
}
void my_Path::write_Path()
{
size_Path();
cout<<"Application path: "<<my_buffer<<endl;
}
int main(int argc, char **argv)
{
my_Path now_Path;
now_Path.size_Path();
now_Path.write_Path();
return 0;
}
Brak komentarzy:
Prześlij komentarz