diff --git a/src/fileops.c b/src/fileops.c index 203cce0a4..da9c55f14 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -33,7 +33,7 @@ int git_futils_mv_atomic(const char *from, const char *to) int git_futils_mkpath2file(const char *file_path) { - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ int error = GIT_SUCCESS; char target_folder_path[GIT_PATH_MAX]; @@ -67,7 +67,7 @@ int git_futils_mktmp(char *path_out, const char *filename) return fd; } -int git_futils_creat_withpath(const char *path, int mode) +int git_futils_creat_withpath(const char *path, const mode_t mode) { if (git_futils_mkpath2file(path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to create file %s", path); @@ -75,13 +75,13 @@ int git_futils_creat_withpath(const char *path, int mode) return p_creat(path, mode); } -int git_futils_creat_locked(const char *path, int mode) +int git_futils_creat_locked(const char *path, const mode_t mode) { int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode); return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create locked file. Could not open %s", path); } -int git_futils_creat_locked_withpath(const char *path, int mode) +int git_futils_creat_locked_withpath(const char *path, const mode_t mode) { if (git_futils_mkpath2file(path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to create locked file %s", path); @@ -289,7 +289,7 @@ int git_futils_direach( return GIT_SUCCESS; } -int git_futils_mkdir_r(const char *path, int mode) +int git_futils_mkdir_r(const char *path, const mode_t mode) { int error, root_path_offset; char *pp, *sp; diff --git a/src/fileops.h b/src/fileops.h index 5b69199d2..176888895 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -48,18 +48,18 @@ extern int git_futils_exists(const char *path); * Create and open a file, while also * creating all the folders in its path */ -extern int git_futils_creat_withpath(const char *path, int mode); +extern int git_futils_creat_withpath(const char *path, const mode_t mode); /** * Create an open a process-locked file */ -extern int git_futils_creat_locked(const char *path, int mode); +extern int git_futils_creat_locked(const char *path, const mode_t mode); /** * Create an open a process-locked file, while * also creating all the folders in its path */ -extern int git_futils_creat_locked_withpath(const char *path, int mode); +extern int git_futils_creat_locked_withpath(const char *path, const mode_t mode); /** * Check if the given path points to a directory @@ -74,7 +74,7 @@ extern int git_futils_isfile(const char *path); /** * Create a path recursively */ -extern int git_futils_mkdir_r(const char *path, int mode); +extern int git_futils_mkdir_r(const char *path, const mode_t mode); /** * Create all the folders required to contain diff --git a/src/posix.c b/src/posix.c index 1b85b053d..7cd0749b6 100644 --- a/src/posix.c +++ b/src/posix.c @@ -17,7 +17,7 @@ int p_open(const char *path, int flags) return open(path, flags | O_BINARY); } -int p_creat(const char *path, int mode) +int p_creat(const char *path, mode_t mode) { return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); } diff --git a/src/posix.h b/src/posix.h index 59bec2794..389578d5b 100644 --- a/src/posix.h +++ b/src/posix.h @@ -42,7 +42,7 @@ extern int p_write(git_file fd, const void *buf, size_t cnt); #define p_close(fd) close(fd) extern int p_open(const char *path, int flags); -extern int p_creat(const char *path, int mode); +extern int p_creat(const char *path, mode_t mode); extern int p_getcwd(char *buffer_out, size_t size); #ifndef GIT_WIN32 diff --git a/src/repository.c b/src/repository.c index 328bc0d57..36642e5ae 100644 --- a/src/repository.c +++ b/src/repository.c @@ -609,7 +609,7 @@ static int repo_init_createhead(git_repository *repo) static int repo_init_structure(const char *git_dir, int is_bare) { - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ int error; char temp_path[GIT_PATH_MAX]; diff --git a/src/win32/posix.h b/src/win32/posix.h index 442717e42..c0af62b1f 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -19,7 +19,7 @@ GIT_INLINE(int) p_link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new)) return -1; } -GIT_INLINE(int) p_mkdir(const char *path, int GIT_UNUSED(mode)) +GIT_INLINE(int) p_mkdir(const char *path, mode_t GIT_UNUSED(mode)) { wchar_t* buf = conv_utf8_to_utf16(path); int ret = _wmkdir(buf); @@ -41,12 +41,12 @@ extern int p_mkstemp(char *tmp_path); extern int p_setenv(const char* name, const char* value, int overwrite); extern int p_stat(const char* path, struct stat* buf); extern int p_chdir(const char* path); -extern int p_chmod(const char* path, int mode); +extern int p_chmod(const char* path, mode_t mode); extern int p_rmdir(const char* path); -extern int p_access(const char* path, int mode); +extern int p_access(const char* path, mode_t mode); extern int p_fsync(int fd); extern int p_open(const char *path, int flags); -extern int p_creat(const char *path, int mode); +extern int p_creat(const char *path, mode_t mode); extern int p_getcwd(char *buffer_out, size_t size); #endif diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index cc17cc71f..bbc496f16 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -230,7 +230,7 @@ int p_open(const char *path, int flags) return fd; } -int p_creat(const char *path, int mode) +int p_creat(const char *path, mode_t mode) { int fd; wchar_t* buf = conv_utf8_to_utf16(path); @@ -268,7 +268,7 @@ int p_chdir(const char* path) return ret; } -int p_chmod(const char* path, int mode) +int p_chmod(const char* path, mode_t mode) { wchar_t* buf = conv_utf8_to_utf16(path); int ret = _wchmod(buf, mode); @@ -355,7 +355,7 @@ int p_snprintf(char *buffer, size_t count, const char *format, ...) return r; } -extern int p_creat(const char *path, int mode); +extern int p_creat(const char *path, mode_t mode); int p_mkstemp(char *tmp_path) { @@ -378,7 +378,7 @@ int p_setenv(const char* name, const char* value, int overwrite) return (SetEnvironmentVariableA(name, value) == 0 ? GIT_EOSERR : GIT_SUCCESS); } -int p_access(const char* path, int mode) +int p_access(const char* path, mode_t mode) { wchar_t *buf = conv_utf8_to_utf16(path); int ret; diff --git a/tests/t10-refs.c b/tests/t10-refs.c index c7bfe4eea..aa6735a30 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -431,7 +431,7 @@ END_TEST BEGIN_TEST(pack0, "create a packfile for an empty folder") git_repository *repo; char temp_path[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); diff --git a/tests/t12-repo.c b/tests/t12-repo.c index de921f9ca..6884188a3 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -173,7 +173,7 @@ END_TEST BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory") char path_repository[GIT_PATH_MAX]; char current_workdir[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ git_repository* repo; must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); @@ -232,7 +232,7 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t char current_workdir[GIT_PATH_MAX]; char path_repository[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0755; /* or 0777 ? */ git_repository* repo; /* Setup the repository to open */ @@ -384,7 +384,7 @@ BEGIN_TEST(discover0, "test discover") char repository_path[GIT_PATH_MAX]; char sub_repository_path[GIT_PATH_MAX]; char found_path[GIT_PATH_MAX]; - int mode = 0755; + mode_t mode = 0755; git_futils_mkdir_r(DISCOVER_FOLDER, mode); must_pass(append_ceiling_dir(ceiling_dirs, TEMP_REPO_FOLDER));