forked from wazuh/wazuh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_op.h
More file actions
157 lines (106 loc) · 4.11 KB
/
file_op.h
File metadata and controls
157 lines (106 loc) · 4.11 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (C) 2015-2019, Wazuh Inc.
* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License (version 2) as published by the FSF - Free Software
* Foundation
*/
/* Functions to handle operation with files */
#ifndef FILE_OP_H
#define FILE_OP_H
#include <stdint.h>
#include <time.h>
#include <sys/stat.h>
#include <external/cJSON/cJSON.h>
#ifdef WIN32
#include <windows.h>
#endif
#define OS_PIDFILE "/var/run"
#define UCS2_LE 1
#define UCS2_BE 2
#ifdef WIN32
typedef uint64_t wino_t;
#else
typedef ino_t wino_t;
#endif
typedef struct File {
char *name;
FILE *fp;
} File;
/* Set the program name - must be done before *anything* else */
void OS_SetName(const char *name) __attribute__((nonnull));
cJSON* getunameJSON();
time_t File_DateofChange(const char *file) __attribute__((nonnull));
ino_t File_Inode(const char *file) __attribute__((nonnull));
off_t FileSize(const char * path);
int IsDir(const char *file) __attribute__((nonnull));
int check_path_type(const char *dir) __attribute__((nonnull));
int IsFile(const char *file) __attribute__((nonnull));
int IsSocket(const char * file) __attribute__((nonnull));
#ifndef WIN32
int IsLink(const char * file) __attribute__((nonnull));
#endif
int CreatePID(const char *name, int pid) __attribute__((nonnull));
char *GetRandomNoise();
int DeletePID(const char *name) __attribute__((nonnull));
void DeleteState();
int MergeFiles(const char *finalpath, char **files, const char *tag) __attribute__((nonnull(1, 2)));
int MergeAppendFile(const char *finalpath, const char *files, const char *tag, int path_offset) __attribute__((nonnull(1)));
int UnmergeFiles(const char *finalpath, const char *optdir, int mode) __attribute__((nonnull(1)));
int TestUnmergeFiles(const char *finalpath, int mode) __attribute__((nonnull(1)));
/* Daemonize a process */
void goDaemon(void);
/* Daemonize a process without closing stdin/stdout/stderr */
void goDaemonLight(void);
/* Not really a file operation, but returns the uname */
const char *getuname(void);
/* Return basename of path */
char *basename_ex(char *path) __attribute__((nonnull));
/* Rename file or directory */
int rename_ex(const char *source, const char *destination) __attribute__((nonnull));
/* Create temporary file */
int mkstemp_ex(char *tmp_path) __attribute__((nonnull));
int TempFile(File *file, const char *source, int copy);
int OS_MoveFile(const char *src, const char *dst);
int w_copy_file(const char *src, const char *dst,char mode,char * message,int silent);
/* Checks for Windows Vista */
#ifdef WIN32
int checkVista();
int isVista;
// Move to the directory where this executable lives in
void w_ch_exec_dir();
#endif
/* Delete directory recursively */
int rmdir_ex(const char *path);
// Delete directory content
int cldir_ex(const char *name);
// Delete directory content with exception list
int cldir_ex_ignore(const char * name, const char ** ignore);
// Make directory recursively
int mkdir_ex(const char * path);
int w_ref_parent_folder(const char * path);
wino_t get_fp_inode(FILE * fp);
long get_fp_size(FILE * fp);
// Read directory and return an array of contained files, sorted alphabetically.
char ** wreaddir(const char * name);
// Open file normally in Linux, allow read/write/delete in Windows
FILE * wfopen(const char * pathname, const char * mode);
/* Delete a line from a file */
int w_remove_line_from_file(char *file, int line);
// To compress an decompress a file in gzip
int w_compress_gzfile(const char *filesrc, const char *filedst);
int w_uncompress_gzfile(const char *gzfilesrc, const char *gzfiledst);
int is_ascii_utf8(const char * file, unsigned int max_lines, unsigned int max_chars_utf8);
int is_usc2(const char * file);
#ifdef WIN32
DWORD FileSizeWin(const char * file);
#endif
int checkBinaryFile(const char *f_name);
int64_t w_ftell (FILE *x);
/* Prevent children processes from inheriting a file pointer */
void w_file_cloexec(FILE * fp);
/* Prevent children processes from inheriting a file descriptor */
void w_descriptor_cloexec(int fd);
#endif /* FILE_OP_H */