Update util functions in ccache.h to match reality

This commit is contained in:
Joel Rosdahl 2011-03-27 23:03:25 +02:00
parent f5b1a3a5fb
commit 1c49fcaa79
2 changed files with 54 additions and 53 deletions

View File

@ -100,27 +100,26 @@ bool hash_file(struct mdfour *md, const char *fname);
void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void cc_log_argv(const char *prefix, char **argv);
void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
void copy_fd(int fd_in, int fd_out);
int copy_file(const char *src, const char *dest, int compress_dest);
int move_file(const char *src, const char *dest, int compress_dest);
int move_uncompressed_file(const char *src, const char *dest,
int compress_dest);
bool file_is_compressed(const char *filename);
int create_dir(const char *dir);
int create_parent_dirs(const char *path);
const char *get_hostname(void);
const char *tmp_string(void);
char *format_hash_as_string(const unsigned char *hash, int size);
int create_hash_dir(char **dir, const char *hash, const char *cache_dir);
int create_cachedirtag(const char *dir);
char *format(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
char *x_strdup(const char *s);
char *x_strndup(const char *s, size_t n);
void *x_realloc(void *ptr, size_t size);
void *x_malloc(size_t size);
void *x_calloc(size_t nmemb, size_t size);
void *x_realloc(void *ptr, size_t size);
void x_asprintf2(char **ptr, const char *format, ...)
ATTR_FORMAT(printf, 2, 3);
void traverse(const char *dir, void (*fn)(const char *, struct stat *));
char *basename(const char *path);
char *dirname(const char *path);
@ -128,8 +127,13 @@ const char *get_extension(const char *path);
char *remove_extension(const char *path);
size_t file_size(struct stat *st);
int safe_create_wronly(const char *fname);
char *format_size(size_t v);
size_t value_units(const char *s);
char *x_realpath(const char *path);
char *gnu_getcwd(void);
#ifndef HAVE_STRTOK_R
char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
int create_empty_file(const char *fname);
const char *get_home_directory(void);
char *get_cwd(void);
@ -140,14 +144,13 @@ bool is_absolute_path(const char *path);
bool is_full_path(const char *path);
void update_mtime(const char *path);
int x_rename(const char *oldpath, const char *newpath);
int x_unlink(const char *path);
int tmp_unlink(const char *path);
int x_unlink(const char *path);
#ifndef _WIN32
char *x_readlink(const char *path);
char *read_text_file(const char *path, size_t size_hint);
bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
#ifndef HAVE_STRTOK_R
char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
bool read_file(const char *path, size_t size_hint, char **data, size_t *size);
char *read_text_file(const char *path, size_t size_hint);
/* ------------------------------------------------------------------------- */
/* stats.c */
@ -160,8 +163,6 @@ void stats_summary(void);
void stats_update_size(enum stats stat, size_t size, unsigned files);
void stats_get_limits(const char *dir, unsigned *maxfiles, unsigned *maxsize);
int stats_set_limits(long maxfiles, long maxsize);
size_t value_units(const char *s);
char *format_size(size_t v);
void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
void stats_read(const char *path, struct counters *counters);
void stats_write(const char *path, struct counters *counters);

84
util.c
View File

@ -76,6 +76,26 @@ log_prefix(void)
#endif
}
#ifndef _WIN32
static long
path_max(const char *path)
{
#ifdef PATH_MAX
(void)path;
return PATH_MAX;
#elif defined(MAXPATHLEN)
(void)path;
return MAXPATHLEN;
#elif defined(_PC_PATH_MAX)
long maxlen = pathconf(path, _PC_PATH_MAX);
if (maxlen >= 4096) {
return maxlen;
} else {
return 4096;
}
#endif
}
/*
* Write a message to the CCACHE_LOGFILE location (adding a newline).
*/
@ -169,28 +189,6 @@ mkstemp(char *template)
}
#endif
#ifndef HAVE_STRTOK_R
/* strtok_r replacement */
char *
strtok_r(char *str, const char *delim, char **saveptr)
{
int len;
char *ret;
if (!str)
str = *saveptr;
len = strlen(str);
ret = strtok(str, delim);
if (ret) {
char *save = ret;
while (*save++);
if ((len + 1) == (intptr_t) (save - str))
save--;
*saveptr = save;
}
return ret;
}
#endif
/*
* Copy src to dest, decompressing src if needed. compress_dest decides whether
* dest will be compressed.
@ -857,26 +855,6 @@ value_units(const char *s)
return (size_t)v;
}
#ifndef _WIN32
static long
path_max(const char *path)
{
#ifdef PATH_MAX
(void)path;
return PATH_MAX;
#elif defined(MAXPATHLEN)
(void)path;
return MAXPATHLEN;
#elif defined(_PC_PATH_MAX)
long maxlen = pathconf(path, _PC_PATH_MAX);
if (maxlen >= 4096) {
return maxlen;
} else {
return 4096;
}
#endif
}
/*
a sane realpath() function, trying to cope with stupid path limits and
a broken API
@ -933,6 +911,28 @@ gnu_getcwd(void)
}
}
#ifndef HAVE_STRTOK_R
/* strtok_r replacement */
char *
strtok_r(char *str, const char *delim, char **saveptr)
{
int len;
char *ret;
if (!str)
str = *saveptr;
len = strlen(str);
ret = strtok(str, delim);
if (ret) {
char *save = ret;
while (*save++);
if ((len + 1) == (intptr_t) (save - str))
save--;
*saveptr = save;
}
return ret;
}
#endif
/* create an empty file */
int
create_empty_file(const char *fname)