34 #ifndef CF_MXE_CROSS_COMPILE 35 #include <sys/param.h> 72 char *tempname = NULL;
76 const int maxretry = 10;
79 for (i = 0; i < maxretry; i++) {
80 tempname = tempnam(dir, pfx);
88 LOG(
llevError,
"Created file detected in tempnam_secure. Someone hoping for a race condition?\n");
95 file = fdopen(fd,
"w+");
97 LOG(
llevError,
"fdopen() failed in tempnam_secure()!\n");
102 *filename = tempname;
119 char buf[strlen(path) +
sizeof(dirent::d_name) + 1];
123 if ((dirp =
opendir(path)) != NULL) {
131 if (de->d_name[0] ==
'.')
137 status = stat(de->d_name, &statbuf);
138 if ((status != -1) && (S_ISDIR(statbuf.st_mode))) {
139 snprintf(
buf,
sizeof(
buf),
"%s/%s", path, de->d_name);
143 snprintf(
buf,
sizeof(
buf),
"%s/%s", path, de->d_name);
151 LOG(
llevError,
"Unable to remove directory %s\n", path);
168 if (!filename || !*filename)
172 while ((cp = strchr(cp+1, (
int)
'/'))) {
174 if (stat(buf, &statbuf) || !S_ISDIR(statbuf.st_mode)) {
181 LOG(
llevError,
"Cannot mkdir %s: %s\n", buf, strerror(errno));
202 void safe_strcat(
char *dest,
const char *orig,
size_t *curlen,
size_t maxlen) {
203 assert(curlen != NULL);
204 assert(*curlen < maxlen);
206 *curlen = strlcat(dest, orig, maxlen);
208 if (*curlen == (maxlen-1))
210 strncpy(dest+*curlen, orig, maxlen-*curlen-1);
212 *curlen += strlen(orig);
214 if (*curlen > (maxlen-1))
222 size_t strlcpy(
char *dst,
const char *src,
size_t size) {
223 strncpy(dst, src, size - 1);
224 dst[size - 1] =
'\0';
232 const char *
strcasestr(
const char *s,
const char *find)
237 if ((c = *find++) != 0) {
238 c =
tolower((
unsigned char) c);
242 if ((sc = *s++) == 0)
245 while ((
char)
tolower((
unsigned char) sc) != c);
247 while (strncasecmp(s, find, len) != 0);
static event_registration c
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
DIR * opendir(const char *)
void make_path_to_file(const char *filename)
Checks if any directories in the given path doesn't exist, and creates if necessary.
Global type definitions and header inclusions.
void remove_directory(const char *path)
This function removes everything in the directory, and the directory itself.
void safe_strcat(char *dest, const char *orig, size_t *curlen, size_t maxlen)
Simple function we use below to keep adding to the same string but also make sure we don't overwrite ...
#define MAX_BUF
Used for all kinds of things.
const char * strcasestr(const char *s, const char *find)
size_t strlcpy(char *dst, const char *src, size_t size)
Portable implementation of strlcpy(3).
FILE * tempnam_secure(const char *dir, const char *pfx, char **filename)
A replacement for the tempnam_local() function since that one is not very secure. ...
Only for debugging purposes.
struct dirent * readdir(DIR *)
#define tolower(C)
Simple macro to convert a letter to lowercase.