summaryrefslogtreecommitdiff
path: root/utils.c
blob: d2704367d273b735a8bc17b8e456b2af0e3ce73f (plain)
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
35
36
37
38
39
40
41
42
43
44
45
#include "utils.h"
#include <unistd.h>

int checkIfFileExists(char *path)
{
	return access(path, F_OK);
}

int detectOsType()
{
	int exists = ERROR;
	for ( int i = 0; i < ENUMSIZE || exists == ERROR; i++ )
	{
		switch (i)
		{
			case pacman:
				if ( checkIfFileExists("/usr/bin/pacman") == 0 )
				{
					exists = i;
				}
				break;

			case apt:
				if ( checkIfFileExists("/usr/bin/apt") == 0 )
				{
					exists = i;
				}
				break;

			case emerge:
				if ( checkIfFileExists("/usr/bin/emerge") == 0 )
				{
					exists = i;
				}
				break;

			case xbps:
				if ( checkIfFileExists("/usr/bin/xbps-install") == 0 )
				{
					exists = i;
				}
		}
	}
	return exists;
}