forked from vi/timeskew
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirectories.h
34 lines (30 loc) · 845 Bytes
/
directories.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Import required libraries
#include <unistd.h>
// Prototypes
void MF_todirname(char * input, int inputlength);
void MF_uplevel(char * input, int inputlength, int levels);
void MF_getdir(char * input, int inputlength);
// Function to get directory of program.
void MF_getdir(char * input, int inputlength)
{
readlink("/proc/self/exe", input, inputlength);
MF_todirname(input, inputlength);
}
// Function to change a file name to the name of the directory containing it.
void MF_todirname(char * input, int inputlength)
{
int previous=0;
for (int i=0; i<inputlength; i++)
{
if (input[i]== 0 ) { input[previous]=0; return; }
if (input[i]=='/') { previous=i; }
}
}
// Function to go up a few levels
void MF_uplevel(char * input, int inputlength, int levels)
{
for (int i=0; i<levels; i++)
{
MF_todirname(input, inputlength);
}
}