summaryrefslogtreecommitdiff
path: root/src/fileops.h
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-11-30 11:27:15 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-07 23:08:15 -0800
commit97769280ba9938ae27f6e06cbd0d5e8a768a86b9 (patch)
tree4fe43e99acb55f904f6b586bd7c5158610f9512f /src/fileops.h
parenta22b14d32dd8d5f06f121aa154d45bac3b10a305 (diff)
downloadlibgit2-97769280ba9938ae27f6e06cbd0d5e8a768a86b9.tar.gz
Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
Diffstat (limited to 'src/fileops.h')
-rw-r--r--src/fileops.h31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/fileops.h b/src/fileops.h
index e1a59f633..df135d0db 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -28,6 +28,7 @@ typedef struct { /* file io buffer */
extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
extern int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated);
extern void git_futils_freebuffer(git_fbuffer *obj);
+extern void git_futils_fbuffer_rtrim(git_fbuffer *obj);
/**
* File utils
@@ -72,9 +73,25 @@ extern int git_futils_isdir(const char *path);
extern int git_futils_isfile(const char *path);
/**
+ * Check if the given path contains the given subdirectory.
+ *
+ * If `append_if_exists` is true, then the subdir will be appended to the
+ * parent path if it does exists.
+ */
+extern int git_futils_contains_dir(git_buf *parent, const char *subdir, int append_if_exists);
+
+/**
+ * Check if the given path contains the given file
+ *
+ * If `append_if_exists` is true, then the filename will be appended to the
+ * parent path if it does exists.
+ */
+extern int git_futils_contains_file(git_buf *parent, const char *file, int append_if_exists);
+
+/**
* Create a path recursively
*/
-extern int git_futils_mkdir_r(const char *path, const mode_t mode);
+extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode);
/**
* Create all the folders required to contain
@@ -85,9 +102,11 @@ extern int git_futils_mkpath2file(const char *path, const mode_t mode);
extern int git_futils_rmdir_r(const char *path, int force);
/**
- * Create and open a temporary file with a `_git2_` suffix
+ * Create and open a temporary file with a `_git2_` suffix.
+ * Writes the filename into path_out.
+ * @return On success, an open file descriptor, else an error code < 0.
*/
-extern int git_futils_mktmp(char *path_out, const char *filename);
+extern int git_futils_mktmp(git_buf *path_out, const char *filename);
/**
* Move a file on the filesystem, create the
@@ -133,16 +152,14 @@ extern void git_futils_mmap_free(git_map *map);
*
* @param pathbuf buffer the function reads the initial directory
* path from, and updates with each successive entry's name.
- * @param pathmax maximum allocation of pathbuf.
* @param fn function to invoke with each entry. The first arg is
* the input state and the second arg is pathbuf. The function
* may modify the pathbuf, but only by appending new text.
* @param state to pass to fn as the first arg.
*/
extern int git_futils_direach(
- char *pathbuf,
- size_t pathmax,
- int (*fn)(void *, char *),
+ git_buf *pathbuf,
+ int (*fn)(void *, git_buf *),
void *state);
extern int git_futils_cmp_path(const char *name1, int len1, int isdir1,