30 #include <sys/types.h>
38 #include "../../common/common.h"
39 #include "../system.h"
47 return getenv(
"HOME");
68 if (stat(fn, &st) == -1) {
69 Com_Printf(
"CompareAttributes: Warning, stat failed: %s\n", name);
73 if ((st.st_mode & S_IFDIR) && (canthave &
SFF_SUBDIR))
76 if ((musthave & SFF_SUBDIR) && !(st.st_mode & S_IFDIR))
87 char*
Sys_FindFirst (
const char* path,
unsigned musthave,
unsigned canhave)
95 if ((p = strrchr(
findbase,
'/')) !=
nullptr) {
107 const struct dirent* d;
108 while ((d = readdir(
fdir)) !=
nullptr) {
130 const struct dirent* d;
131 while ((d = readdir(
fdir)) !=
nullptr) {
149 #define MAX_FOUND_FILES 0x1000
155 if (subdirs[0] !=
'\0') {
156 Com_sprintf(search,
sizeof(search),
"%s/%s", basedir, subdirs);
158 Com_sprintf(search,
sizeof(search),
"%s", basedir);
162 if ((directory = opendir(search)) ==
nullptr)
166 const struct dirent* d;
169 while ((d = readdir(directory)) !=
nullptr) {
170 Com_sprintf(filename,
sizeof(filename),
"%s/%s", search, d->d_name);
171 if (stat(filename, &st) == -1)
174 if (st.st_mode & S_IFDIR) {
177 if (subdirs[0] !=
'\0') {
178 Com_sprintf(newsubdirs,
sizeof(newsubdirs),
"%s/%s", subdirs, d->d_name);
180 Com_sprintf(newsubdirs,
sizeof(newsubdirs),
"%s", d->d_name);
185 Com_sprintf(filename,
sizeof(filename),
"%s/%s", subdirs, d->d_name);
201 if (getcwd(cwd,
sizeof(cwd) - 1) ==
nullptr)
210 if (mkdir(thePath, 0777) != -1)
214 Com_Printf(
"\"mkdir %s\" failed, reason: \"%s\".", thePath, strerror(errno));
222 if (!stat(ospath, &buf) && S_ISFIFO(buf.st_mode))
225 const int result = mkfifo(ospath, 0600);
231 const int fn = fileno(fifo);
232 fcntl(fn, F_SETFL, O_NONBLOCK);
235 Com_Printf(
"WARNING: Could not create fifo pipe at %s.\n", ospath);
242 return fopen(filename, mode);
252 return rename(oldname, newname);
257 return access(filename, mode);
FILE * Sys_Fopen(const char *filename, const char *mode)
void Sys_Error(const char *error,...)
void Sys_ListFilteredFiles(const char *basedir, const char *subdirs, const char *filter, linkedList_t **list)
char * Sys_FindNext(unsigned musthave, unsigned canhave)
Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask...
int Sys_Access(const char *filename, int mode)
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void FS_RemoveFile(const char *osPath)
void Com_Printf(const char *const fmt,...)
static char findbase[MAX_OSPATH]
int Sys_Rename(const char *oldname, const char *newname)
static char findpath[MAX_OSPATH]
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
void LIST_AddString(linkedList_t **listDest, const char *data)
Adds an string to a new or to an already existing linked list. The string is copied here...
int Com_Filter(const char *pattern, const char *text)
Match the pattern PATTERN against the string TEXT;.
void Sys_Mkdir(const char *thePath)
char * Sys_FindFirst(const char *path, unsigned musthave, unsigned canhave)
Opens the directory and returns the first file that matches our searchrules.
static char findpattern[MAX_OSPATH]
#define Q_strcasecmp(a, b)
char * Sys_GetHomeDirectory(void)
Returns the home environment variable (which hold the path of the user's homedir) ...
int Sys_Remove(const char *filename)
void Sys_Mkfifo(const char *ospath, qFILE *f)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
static bool CompareAttributes(const char *path, const char *name, unsigned musthave, unsigned canthave)
void Sys_NormPath(char *path)