aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Nemerson <evan@nemerson.com>2016-11-02 06:03:06 -0700
committerEugene Kliuchnikov <eustas@google.com>2016-11-02 14:03:06 +0100
commit12750768c25cbe44f38e902c9ef37bdce74ddb25 (patch)
treed7c9309bdda9d8fbe0310c3d41e441e2d320ec5f
parent6c470098928f6dbd76bca47ac61eaa6b9802ba94 (diff)
downloadbrotli-12750768c25cbe44f38e902c9ef37bdce74ddb25.zip
brotli-12750768c25cbe44f38e902c9ef37bdce74ddb25.tar.gz
brotli-12750768c25cbe44f38e902c9ef37bdce74ddb25.tar.bz2
bro: check return values of chown and chmod (#465)
Apparently some libc versions declare chown with the warn_unused_result attribute, which is enabled by default.
-rw-r--r--tools/bro.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/bro.c b/tools/bro.c
index d8d7da7..07cef95 100644
--- a/tools/bro.c
+++ b/tools/bro.c
@@ -42,8 +42,8 @@
#define fopen ms_fopen
#define open ms_open
-#define chmod(F, P)
-#define chown(F, O, G)
+#define chmod(F, P) (0)
+#define chown(F, O, G) (0)
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#define fseek _fseeki64
@@ -248,6 +248,7 @@ static int64_t FileSize(const char *path) {
static void CopyStat(const char* input_path, const char* output_path) {
struct stat statbuf;
struct utimbuf times;
+ int res;
if (input_path == 0 || output_path == 0) {
return;
}
@@ -257,9 +258,15 @@ static void CopyStat(const char* input_path, const char* output_path) {
times.actime = statbuf.st_atime;
times.modtime = statbuf.st_mtime;
utime(output_path, &times);
- chmod(output_path, statbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
- chown(output_path, (uid_t)-1, statbuf.st_gid);
- chown(output_path, statbuf.st_uid, (gid_t)-1);
+ res = chmod(output_path, statbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
+ if (res != 0)
+ perror("chmod failed");
+ res = chown(output_path, (uid_t)-1, statbuf.st_gid);
+ if (res != 0)
+ perror("chown failed");
+ res = chown(output_path, statbuf.st_uid, (gid_t)-1);
+ if (res != 0)
+ perror("chown failed");
}
/* Result ownersip is passed to caller.