fileops/posix: replace usage of "int mode" with "mode_t mode" Note: Functions exported from fileops take const mode_t, while the underlying POSIX wrappers take mode_t.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
diff --git a/src/fileops.c b/src/fileops.c
index 203cce0..da9c55f 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 5b69199..1768888 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 1b85b05..7cd0749 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 59bec27..389578d 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 328bc0d..36642e5 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 442717e..c0af62b 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 cc17cc7..bbc496f 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 c7bfe4e..aa6735a 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 de921f9..6884188 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));