-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
60 lines (45 loc) · 1.1 KB
/
util.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// chsys: util
// (c) giantdwarf 2022
// module containing utility functions for chsys package manager
//
#pragma once
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
/*#ifdef //if system is 64 bit
#define SYSOFSET uint64_t
#else
#define SYSOFSET uint32_t
#enif*/
#define ARRAY_LENGTH(a) sizeof(a) / sizeof(a[1])
//Concat two strings into one
char* concat(char* a, char* b);
//Split one string into many, based on given delimeter
char** split(char* a, char delim);
int copy_file(char* src, char* dest);
//=============================
// IMPORTANT WARNING!
// This mutex implementation is
// NOT deadlock secure!
//
// USE AT OWN RISK!
//=============================
typedef struct {
int lock;
} Mutex;
Mutex* create_mutex(char* lock_file);
int destroy_mutex(Mutex* m);
//Lock. If locked, wait till unlocked
int lock(Mutex* m);
//Try locking. If locked, exit imidiately
int try_lock(Mutex* m);
//Unlock mutex
int unlock(Mutex* m);